3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php$input = 'coilovers[strut_and_individual_components][complete_strut][][achse]'); $output = array(); $pointer = $output;while( ($index = strpos( $input, '[')) !== false) { if( $index != 0) { $key = substr( $input, 0, $index); $pointer[$key] = array(); $pointer = $pointer[$key]; } $end_index = strpos( $input, ']'); $array_key = substr( $input, $index, $end_index); $pointer[$array_key] = array(); $pointer = $pointer[$array_key]; $input = substr( $input, $end_index); echo "$input\n";} <?php
Output for 5.4.0 - 5.5.15
Parse error: syntax error, unexpected '$input' (T_VARIABLE) in /in/0NprR on line 1
Process exited with code 255.
Output for 4.3.0 - 5.3.29
<?php$input = 'coilovers[strut_and_individual_components][complete_strut][][achse]'); $output = array(); $pointer = $output;while( ($index = strpos( $input, '[')) !== false) { if( $index != 0) { $key = substr( $input, 0, $index); $pointer[$key] = array(); $pointer = $pointer[$key]; } $end_index = strpos( $input, ']'); $array_key = substr( $input, $index, $end_index); $pointer[$array_key] = array(); $pointer = $pointer[$array_key]; $input = substr( $input, $end_index); echo "$input\n";} <?php