array_map_variation1.phpt 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test array_map() function : usage variations - string keys
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...])
  6. * Description: Applies the callback to the elements in given arrays.
  7. * Source code: ext/standard/array.c
  8. */
  9. echo "*** Testing array_map() : string keys ***\n";
  10. $arr = array("stringkey" => "value");
  11. function cb1 ($a) {return array ($a);};
  12. function cb2 ($a,$b) {return array ($a,$b);};
  13. var_dump( array_map("cb1", $arr));
  14. var_dump( array_map("cb2", $arr,$arr));
  15. var_dump( array_map(null, $arr));
  16. var_dump( array_map(null, $arr, $arr));
  17. echo "Done";
  18. ?>
  19. --EXPECT--
  20. *** Testing array_map() : string keys ***
  21. array(1) {
  22. ["stringkey"]=>
  23. array(1) {
  24. [0]=>
  25. string(5) "value"
  26. }
  27. }
  28. array(1) {
  29. [0]=>
  30. array(2) {
  31. [0]=>
  32. string(5) "value"
  33. [1]=>
  34. string(5) "value"
  35. }
  36. }
  37. array(1) {
  38. ["stringkey"]=>
  39. string(5) "value"
  40. }
  41. array(1) {
  42. [0]=>
  43. array(2) {
  44. [0]=>
  45. string(5) "value"
  46. [1]=>
  47. string(5) "value"
  48. }
  49. }
  50. Done