3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Recursion { private static function printArray() { print_r(self::$array); } public static function recursionInitiatorParent($information, $list) { self::$array = $information; self::$keylist = $list; $keywords = explode(",", self::$keylist); echo "Before: \n\n"; self::printArray(); foreach($keywords as $key) self::recursionInitiator(self::$array, $key); echo "\n======================================= \n\n"; self::printArray(); } private static function recursionInitiator($array, $key) { if(count($array) < 1) return; foreach($array as $record) { if(is_array($record)) recursionInitiator($record, $key); else { foreach($record as $key_internal=>$value_internal) if($key_internal === $key) $value_internal = self::$asterisk; } } } private static $asterisk = "**"; private static $array; private static $keylist; } $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 = "telephone,iin"; Recursion::recursionInitiatorParent($information, $list);
based on LSGaD
Output for 7.0.0 - 7.2.0
Before: 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 ) Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Fatal error: Uncaught Error: Call to undefined function recursionInitiator() in /in/uCRJb:34 Stack trace: #0 /in/uCRJb(20): Recursion::recursionInitiator(Array, 'telephone') #1 /in/uCRJb(59): Recursion::recursionInitiatorParent(Array, 'telephone,iin') #2 {main} thrown in /in/uCRJb on line 34
Process exited with code 255.
Output for 5.3.19 - 5.6.21
Before: 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 ) Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Warning: Invalid argument supplied for foreach() in /in/uCRJb on line 38 Fatal error: Call to undefined function recursionInitiator() in /in/uCRJb on line 34
Process exited with code 255.