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($a, $key) { if(count($a) < 1) return; foreach($a as $record) { if(is_array($record)) { foreach($record as $key_internal=>$value_internal) if($key_internal === $key) $value_internal = self::$asterisk; } else self::recursionInitiator($record, $key); } } 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 KWtXY
Output for 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: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: count(): Parameter must be an array or an object that implements Countable in /in/FlIbB on line 28 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 ======================================= 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 )
Output for 5.3.19 - 7.1.10
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/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 Warning: Invalid argument supplied for foreach() in /in/FlIbB on line 31 ======================================= 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 )