1--TEST-- 2Test each() function : usage variations - Multi-dimensional arrays 3--FILE-- 4<?php 5/* Prototype : array each(array $arr) 6 * Description: Return the currently pointed key..value pair in the passed array, 7 * and advance the pointer to the next element 8 * Source code: Zend/zend_builtin_functions.c 9 */ 10 11/* 12 * Test behaviour of each() when passed: 13 * 1. a two-dimensional array 14 * 2. a sub-array 15 */ 16 17echo "*** Testing each() : usage variations ***\n"; 18 19$arr = array ('zero', 20 array(1, 2, 3), 21 'one' => 'un', 22 array('a', 'b', 'c') 23 ); 24 25echo "\n-- Pass each() a two-dimensional array --\n"; 26for ($i = 1; $i < count($arr); $i++) { 27 var_dump( each($arr) ); 28} 29 30echo "\n-- Pass each() a sub-array --\n"; 31var_dump( each($arr[2])); 32 33echo "Done"; 34?> 35--EXPECTF-- 36*** Testing each() : usage variations *** 37 38-- Pass each() a two-dimensional array -- 39array(4) { 40 [1]=> 41 string(4) "zero" 42 ["value"]=> 43 string(4) "zero" 44 [0]=> 45 int(0) 46 ["key"]=> 47 int(0) 48} 49array(4) { 50 [1]=> 51 array(3) { 52 [0]=> 53 int(1) 54 [1]=> 55 int(2) 56 [2]=> 57 int(3) 58 } 59 ["value"]=> 60 array(3) { 61 [0]=> 62 int(1) 63 [1]=> 64 int(2) 65 [2]=> 66 int(3) 67 } 68 [0]=> 69 int(1) 70 ["key"]=> 71 int(1) 72} 73array(4) { 74 [1]=> 75 string(2) "un" 76 ["value"]=> 77 string(2) "un" 78 [0]=> 79 string(3) "one" 80 ["key"]=> 81 string(3) "one" 82} 83 84-- Pass each() a sub-array -- 85array(4) { 86 [1]=> 87 string(1) "a" 88 ["value"]=> 89 string(1) "a" 90 [0]=> 91 int(0) 92 ["key"]=> 93 int(0) 94} 95Done 96