array_map_variation11.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --TEST--
  2. Test array_map() function : usage variations - with recursive callback
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] )
  6. * Description: Applies the callback to the elements of the given arrays
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test array_map() by passing subarrays and recursive callback function
  11. */
  12. echo "*** Testing array_map() : recursive callback function ***\n";
  13. // callback function
  14. function square_recur_single_array($var) {
  15. if (is_array($var))
  16. return array_map('square_recur_single_array', $var);
  17. return $var * $var;
  18. }
  19. $array1 = array(1, array(2, 3, array(5)), array(4));
  20. var_dump( array_map('square_recur_single_array', $array1));
  21. echo "Done";
  22. ?>
  23. --EXPECTF--
  24. *** Testing array_map() : recursive callback function ***
  25. array(3) {
  26. [0]=>
  27. int(1)
  28. [1]=>
  29. array(3) {
  30. [0]=>
  31. int(4)
  32. [1]=>
  33. int(9)
  34. [2]=>
  35. array(1) {
  36. [0]=>
  37. int(25)
  38. }
  39. }
  40. [2]=>
  41. array(1) {
  42. [0]=>
  43. int(16)
  44. }
  45. }
  46. Done