3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [ [ "FirstName" => "Tom", "LastName" => "Jones", "EmployeeID" => "123", "ManagerEmployeeID" => "", "Manager Name" => "", ], [ "FirstName" => "Alice", "LastName" => "Wong", "EmployeeID" => "456", "ManagerEmployeeID" => "123", "Manager Name" => "Tom Jones", ], [ "FirstName" => "Tommy", "LastName" => "J.", "EmployeeID" => "654", "ManagerEmployeeID" => "123", "Manager Name" => "Tom Jones", ], [ "FirstName" => "Billy", "LastName" => "Bob", "EmployeeID" => "777", "ManagerEmployeeID" => "", "Manager Name" => "", ], [ "FirstName" => "Rik", "LastName" => "A.", "EmployeeID" => "622", "ManagerEmployeeID" => "777", "Manager Name" => "Billy Bob", ], [ "FirstName" => "Bob", "LastName" => "Small", "EmployeeID" => "111", "ManagerEmployeeID" => "622", "Manager Name" => "Rik A.", ], [ "FirstName" => "Small", "LastName" => "Jones", "EmployeeID" => "098", "ManagerEmployeeID" => "622", "Manager Name" => "Rik A", ], [ "FirstName" => "Eric", "LastName" => "C.", "EmployeeID" => "222", "ManagerEmployeeID" => "777", "Manager Name" => "Billy Bob", ]]; // print_r($array); function getTreeData($data=[], $parent_key='', $self_key, &$new_array=[]) { if(!empty($data)) { foreach($data as $d) { if(empty($new_array)) {} } /*if(!empty($data[$parent_key])) { // $new_array[] }*/ } else { return $data; } } getTreeData($array, "ManagerEmployeeID", "EmployeeID"); // $master_data;
based on nfMti
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0beta1