3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Recursion { private static function printArray($a) { print_r($a); } public static function recursionInitiatorParent($information, $list) { self::$array = $information; self::$keylist = $list; $keywords = explode(",", self::$keylist); echo "Before: \n\n"; self::printArray(self::$array); //foreach($keywords as $key) self::recursionInitiator(self::$array, $key); echo "\n======================================= \n\n"; self::printArray(self::$array); } private static function recursionInitiator($a, $key) { if(count($array) < 1) return; foreach($a as $record) { if(is_array($record)) { self::recursionInitiator($record, $key); // echo "\n"; // self::printArray($record); } else { $record[0] = self::$asterisk; // foreach($record as $k=>$v) // if($k == $key) // $record[$k] = self::$asterisk; // echo "\n" . $record; } } } 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 FjVjK
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 ) Notice: Undefined variable: key in /in/nppUt on line 20 Notice: Undefined variable: array in /in/nppUt on line 28 Warning: count(): Parameter must be an array or an object that implements Countable in /in/nppUt on line 28 ======================================= 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 ) Notice: Undefined variable: key in /in/nppUt on line 20 Notice: Undefined variable: array in /in/nppUt on line 28 ======================================= 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 )