3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function setKey($session_keys, $value) { $current_key = ''; $counter = 0; $prev_step = $_SESSION; try { $session_keys_array = explode(':', $session_keys); krsort($session_keys_array); $c = count($session_keys_array); $count = 0; $arr = array(); foreach ($session_keys_array as $key) { $count++; switch ($count) { case 1: $arr[$key] = $value; break; case ($count > 1 AND $count < $c): $arr[$key] = $arr; break; case $c: $_SESSION[$key] = $arr; break; } } } catch (Exception $e) { //TODO:log notice if Session[currentKey] is not an array return false; } return array_key_exists($key,$prev_step) && eval('!empty($_SESSION' . $current_key . ');'); } $_SESSION['1']['2']['3'] = 'zzzz'; setKey('1:2:3', 77); echo $_SESSION['1']['2']['3']; print_f($_SESSION);
based on 93dRp
Output for 7.0.0 - 7.2.0
77 Fatal error: Uncaught Error: Call to undefined function print_f() in /in/srZoI:44 Stack trace: #0 {main} thrown in /in/srZoI on line 44
Process exited with code 255.
Output for 5.3.21 - 5.3.24, 5.3.26 - 5.6.28
77 Fatal error: Call to undefined function print_f() in /in/srZoI on line 44
Process exited with code 255.
Output for 5.3.25

Process exited with code 137.