3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Recursion { public static function recursionLevelOne($information, $keylist) { $global_array = array(); $keys = explode($keylist, ","); foreach($keys as $individual_key) $global_array = self::recursionLevelTwo($information, $individual_key); return $global_array; } private static function recursionLevelTwo($array, $key) { if(count($array) == 0) return; $global_array = array(); foreach($array as $k => $v) { if($k == $key) if($array[$k] != self::$asterisk) $array[$k] = self::$asterisk; else { if(is_array($v)) { $temp_array = self::recursionLevelTwo($v, $key); array_push($global_array, $temp_array); } } } return $global_array; } private static $asterisk = "**"; } $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", "telephone" => "someOtherTelephoneNumber555"); $list = "login,customer_id"; print_r($information); echo PHP.EOL; echo PHP.EOL; $global_array = Recursion::recursionLevelOne($information, $list); print_r($global_array);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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 [telephone] => someOtherTelephoneNumber555 ) Fatal error: Uncaught Error: Undefined constant "PHP" in /in/RLUaq:57 Stack trace: #0 {main} thrown in /in/RLUaq on line 57
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
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 [telephone] => someOtherTelephoneNumber555 ) Warning: Use of undefined constant PHP - assumed 'PHP' (this will throw an Error in a future version of PHP) in /in/RLUaq on line 57 Warning: Use of undefined constant EOL - assumed 'EOL' (this will throw an Error in a future version of PHP) in /in/RLUaq on line 57 PHPEOL Warning: Use of undefined constant PHP - assumed 'PHP' (this will throw an Error in a future version of PHP) in /in/RLUaq on line 58 Warning: Use of undefined constant EOL - assumed 'EOL' (this will throw an Error in a future version of PHP) in /in/RLUaq on line 58 PHPEOLArray ( )
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.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 [telephone] => someOtherTelephoneNumber555 ) Notice: Use of undefined constant PHP - assumed 'PHP' in /in/RLUaq on line 57 Notice: Use of undefined constant EOL - assumed 'EOL' in /in/RLUaq on line 57 PHPEOL Notice: Use of undefined constant PHP - assumed 'PHP' in /in/RLUaq on line 58 Notice: Use of undefined constant EOL - assumed 'EOL' in /in/RLUaq on line 58 PHPEOLArray ( )

preferences:
158.62 ms | 404 KiB | 183 Q