3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function test_print($item, $key) { echo "$key holds $item\n"; } function recursion($array, $key_parent) { if(count($array) == 0) return; foreach (new RecursiveIteratorIterator( new RecursiveArrayIterator($array), RecursiveIteratorIterator::CATCH_GET_CHILD) as $key => $value) { if(is_array($value)) { echo 'My Array Node ' . $key; recursion($value); } else { //echo 'My node ' . $key . ' with value ' . $value . PHP_EOL; if($key == $key_parent) $array[$key] = "**"; } } } $information = array("login" => "someUsername", "password" => "somePassword", "card_pin"=>"card_1234", "pin"=>"pin_356", "iin" => "iin_123", "shipping" => array("telephone" => "telephone_998"), "cardnumber" => "card_number_876", "customer_id" => "customer_654"); $list = "login,customer_id"; print_r($information); //array_walk_recursive($information, 'test_print'); recursion($information, "login"); print_r($information);
based on qVJbI
Output for 7.1.0 - 7.2.0
Array ( [login] => someUsername [password] => somePassword [card_pin] => card_1234 [pin] => pin_356 [iin] => iin_123 [shipping] => Array ( [telephone] => telephone_998 ) [cardnumber] => card_number_876 [customer_id] => customer_654 ) My Array Node shipping Fatal error: Uncaught ArgumentCountError: Too few arguments to function recursion(), 1 passed in /in/V7cui on line 21 and exactly 2 expected in /in/V7cui:8 Stack trace: #0 /in/V7cui(21): recursion(Array) #1 /in/V7cui(44): recursion(Array, 'login') #2 {main} thrown in /in/V7cui on line 8
Process exited with code 255.
Output for 5.3.19 - 7.0.20
Array ( [login] => someUsername [password] => somePassword [card_pin] => card_1234 [pin] => pin_356 [iin] => iin_123 [shipping] => Array ( [telephone] => telephone_998 ) [cardnumber] => card_number_876 [customer_id] => customer_654 ) My Array Node shipping Warning: Missing argument 2 for recursion(), called in /in/V7cui on line 21 and defined in /in/V7cui on line 8 Notice: Undefined variable: key_parent in /in/V7cui on line 27 Array ( [login] => someUsername [password] => somePassword [card_pin] => card_1234 [pin] => pin_356 [iin] => iin_123 [shipping] => Array ( [telephone] => telephone_998 ) [cardnumber] => card_number_876 [customer_id] => customer_654 )