3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = '{"9":{"id":"9","btc_mlm_user_id":"0","lft":"1","rht":"16","lvl":"0","name":"Root","created":"2017-06-27 05:56:11","modified":"2017-06-27 05:56:11","first_name":"","last_name":"","username":""},"42":{"id":"42","btc_mlm_user_id":"25","lft":"2","rht":"13","lvl":"1","name":"naresh","created":"2017-11-02 10:22:24","modified":"2017-11-02 10:22:24","first_name":"","last_name":"","username":"naresh"},"44":{"id":"44","btc_mlm_user_id":"27","lft":"3","rht":"4","lvl":"2","name":"rahul1","created":"2017-11-02 10:25:53","modified":"2017-11-02 10:25:53","first_name":"","last_name":"","username":"rahul1"},"45":{"id":"45","btc_mlm_user_id":"28","lft":"5","rht":"6","lvl":"2","name":"rahul123","created":"2017-11-02 10:27:19","modified":"2017-11-02 10:27:19","first_name":"","last_name":"","username":"rahul123"},"46":{"id":"46","btc_mlm_user_id":"29","lft":"7","rht":"12","lvl":"2","name":"kapil1","created":"2017-11-02 10:28:20","modified":"2017-11-02 10:28:20","first_name":"","last_name":"","username":"kapil1"},"47":{"id":"47","btc_mlm_user_id":"30","lft":"8","rht":"11","lvl":"3","name":"priya12","created":"2017-11-02 10:30:30","modified":"2017-11-02 10:30:30","first_name":"","last_name":"","username":"priya12"},"48":{"id":"48","btc_mlm_user_id":"31","lft":"9","rht":"10","lvl":"4","name":"amit12","created":"2017-11-02 10:32:00","modified":"2017-11-02 10:32:00","first_name":"","last_name":"","username":"amit12"},"43":{"id":"43","btc_mlm_user_id":"26","lft":"14","rht":"15","lvl":"1","name":"roshan","created":"2017-11-02 10:24:27","modified":"2017-11-02 10:24:27","first_name":"","last_name":"","username":"roshan"}}'; $t = []; function tree($data, $left = 0, $right = null) { $tree = array(); foreach ($data as $key => $value) { if ($value['lft'] == $left + 1 && (is_null($right) || $value['rht'] < $right)) { $child = []; $child['text'] = ['name' => $value['name']]; $childTree = tree($data, $value['lft'], $value['rht']); if (!empty($childTree)) { $child['children'] = $childTree; } $tree[] = $child; $left = $value['rht']; } } return $tree; } $tree = tree(json_decode($category, true))[0]; print_r($tree); echo preg_replace('/"(\w+)":/','$1:',json_encode($tree));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [text] => Array ( [name] => Root ) [children] => Array ( [0] => Array ( [text] => Array ( [name] => naresh ) [children] => Array ( [0] => Array ( [text] => Array ( [name] => rahul1 ) ) [1] => Array ( [text] => Array ( [name] => rahul123 ) ) [2] => Array ( [text] => Array ( [name] => kapil1 ) [children] => Array ( [0] => Array ( [text] => Array ( [name] => priya12 ) [children] => Array ( [0] => Array ( [text] => Array ( [name] => amit12 ) ) ) ) ) ) ) ) [1] => Array ( [text] => Array ( [name] => roshan ) ) ) ) {text:{name:"Root"},children:[{text:{name:"naresh"},children:[{text:{name:"rahul1"}},{text:{name:"rahul123"}},{text:{name:"kapil1"},children:[{text:{name:"priya12"},children:[{text:{name:"amit12"}}]}]}]},{text:{name:"roshan"}}]}

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.74 ms | 409 KiB | 8 Q