3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr_input = array(); $arr_input[1] = array("parent_id"=>"null", "name"=>"one"); $arr_input[2] = array("parent_id"=>"1", "name"=>"two"); $arr_input[3] = array("parent_id"=>"null", "name"=>"three"); $arr_input[4] = array("parent_id"=>"3", "name"=>"four"); $arr_input[5] = array("parent_id"=>"4", "name"=>"five"); $arr_input[6] = array("parent_id"=>"2", "name"=>"six"); $arr_input[7] = array("parent_id"=>"3", "name"=>"seven"); $arr_input[8] = array("parent_id"=>"2", "name"=>"eight"); $input_id = 6; // variable input if(isset($arr_input[$input_id])) { echo $arr_input[$input_id]['name']; $parent_id = $arr_input[$input_id]['parent_id']; while($parent_id!='null') { if(isset($arr_input[$parent_id])) { echo "/".$arr_input[$parent_id]['name']; } $parent_id = $arr_input[$parent_id]['parent_id']; } }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.5 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
six/two/one

preferences:
266.59 ms | 406 KiB | 378 Q