array_combine_basic.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. Test array_combine() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_combine(array $keys, array $values)
  6. * Description: Creates an array by using the elements of the first parameter as keys
  7. * and the elements of the second as the corresponding values
  8. * Source code: ext/standard/array.c
  9. */
  10. echo "*** Testing array_combine() : basic functionality ***\n";
  11. /* Different arrays for $keys and $values arguments */
  12. // array with default keys for $keys and $values arguments
  13. $keys_array = array(1, 2);
  14. $values_array = array(3,4);
  15. var_dump( array_combine($keys_array, $values_array) );
  16. // associative arrays for $keys and $values arguments
  17. $keys_array = array(1 => "a", 2 => 'b');
  18. $values_array = array(3 => 'c', 4 => "d");
  19. var_dump( array_combine($keys_array, $values_array) );
  20. // mixed array for $keys and $values arguments
  21. $keys_array = array(1, 2 => "b");
  22. $values_array = array(3 => 'c', 4);
  23. var_dump( array_combine($keys_array, $values_array) );
  24. echo "Done";
  25. ?>
  26. --EXPECTF--
  27. *** Testing array_combine() : basic functionality ***
  28. array(2) {
  29. [1]=>
  30. int(3)
  31. [2]=>
  32. int(4)
  33. }
  34. array(2) {
  35. ["a"]=>
  36. string(1) "c"
  37. ["b"]=>
  38. string(1) "d"
  39. }
  40. array(2) {
  41. [1]=>
  42. string(1) "c"
  43. ["b"]=>
  44. int(4)
  45. }
  46. Done