current_variation4.phpt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. Test current() function : usage variations - multi-dimensional arrays
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed current(array $array_arg)
  6. * Description: Return the element currently pointed to by the internal array pointer
  7. * Source code: ext/standard/array.c
  8. * Alias to functions: pos
  9. */
  10. /*
  11. * Test how current() behaves with muti-dimensional and recursive arrays
  12. */
  13. echo "*** Testing current() : usage variations ***\n";
  14. echo "\n-- Two Dimensional Array --\n";
  15. $multi_array = array ('zero', array (1, 2, 3), 'two');
  16. echo "Initial Position: ";
  17. var_dump(current($multi_array));
  18. echo "Next Position: ";
  19. next($multi_array);
  20. var_dump(current($multi_array));
  21. echo "End Position: ";
  22. end($multi_array);
  23. var_dump(current($multi_array));
  24. echo "\n-- Access an Array Within an Array --\n";
  25. //accessing an array within an array
  26. echo "Initial Position: ";
  27. var_dump(current($multi_array[1]));
  28. echo "\n-- Recursive, Multidimensional Array --\n";
  29. //create a recursive array
  30. $multi_array[] = &$multi_array;
  31. //See where internal pointer is after adding more elements
  32. echo "Current Position: ";
  33. var_dump(current($multi_array));
  34. //see if internal pointer is in same position as referenced array
  35. var_dump(current($multi_array[3][3][3]));
  36. // see if internal pointer is in the same position from when accessing this inner array
  37. var_dump(current($multi_array[3][3][3][1]));
  38. ?>
  39. ===DONE===
  40. --EXPECTF--
  41. *** Testing current() : usage variations ***
  42. -- Two Dimensional Array --
  43. Initial Position: string(4) "zero"
  44. Next Position: array(3) {
  45. [0]=>
  46. int(1)
  47. [1]=>
  48. int(2)
  49. [2]=>
  50. int(3)
  51. }
  52. End Position: string(3) "two"
  53. -- Access an Array Within an Array --
  54. Initial Position: int(1)
  55. -- Recursive, Multidimensional Array --
  56. Current Position: string(3) "two"
  57. string(3) "two"
  58. int(1)
  59. ===DONE===