I have an array like this:
Array (
[0] => Array ( [id] => 1000 [enroller_id] => 1005)
[1] => Array ( [id] => 1005 [enroller_id] =>)
[2
This will do what you want, except it does not put the first element (1005) in the array:
function create_array($number, $data)
{
$result = array();
foreach ($data as $row)
{
if ($row['enroller_id'] == $number)
{
$result[$row['id']] = create_array($row['id'], $data);
}
}
return $result;
}
print_r(create_array(1005, $data));
Output:
Array
(
[1000] => Array
(
[1101] => Array ()
[1111] => Array ()
)
)