1--TEST-- 2Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays 3--FILE-- 4<?php 5/* 6 * Passing 'input' argument as an associative array 7 * with Numeric & string keys 8*/ 9 10echo "*** Testing array_walk_recursive() : 'input' as an associative array ***\n"; 11 12function for_numeric($value, $key, $user_data) 13{ 14 // dump the input values to see if they are 15 // passed with correct type 16 var_dump($key); 17 var_dump($value); 18 var_dump($user_data); 19 echo "\n"; // new line to separate the output between each element 20} 21 22function for_string($value, $key) 23{ 24 // dump the input values to see if they are 25 // passed with correct type 26 var_dump($key); 27 var_dump($value); 28 echo "\n"; // new line to separate the output between each element 29} 30 31function for_mixed($value, $key) 32{ 33 // dump the input values to see if they are 34 // passed with correct type 35 var_dump($key); 36 var_dump($value); 37 echo "\n"; // new line to separate the output between each element 38} 39 40// Numeric keys 41$input = array( 0 => array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30)); 42echo "-- Associative array with numeric keys --\n"; 43var_dump( array_walk_recursive($input, "for_numeric", 10)); 44 45// String keys 46$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange")); 47echo "-- Associative array with string keys --\n"; 48var_dump( array_walk_recursive($input, "for_string")); 49 50// binary key 51$input = array( b"a" => "Apple", b"b" => "Banana"); 52echo "-- Associative array with binary keys --\n"; 53var_dump( array_walk_recursive($input, "for_string")); 54 55// Mixed keys - numeric/string 56$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3); 57echo "-- Associative array with numeric/string keys --\n"; 58var_dump( array_walk_recursive($input, "for_mixed")); 59 60echo "Done" 61?> 62--EXPECT-- 63*** Testing array_walk_recursive() : 'input' as an associative array *** 64-- Associative array with numeric keys -- 65int(1) 66int(25) 67int(10) 68 69int(5) 70int(12) 71int(10) 72 73int(0) 74int(-80) 75int(10) 76 77int(-2) 78int(100) 79int(10) 80 81int(5) 82int(30) 83int(10) 84 85bool(true) 86-- Associative array with string keys -- 87string(1) "a" 88string(5) "Apple" 89 90string(1) "b" 91string(7) "Bananna" 92 93string(1) "c" 94string(6) "carrot" 95 96string(1) "o" 97string(6) "Orange" 98 99bool(true) 100-- Associative array with binary keys -- 101string(1) "a" 102string(5) "Apple" 103 104string(1) "b" 105string(6) "Banana" 106 107bool(true) 108-- Associative array with numeric/string keys -- 109int(0) 110int(1) 111 112int(1) 113int(2) 114 115string(1) "a" 116string(5) "Apple" 117 118string(1) "b" 119string(6) "Banana" 120 121int(2) 122int(3) 123 124bool(true) 125Done 126