<?php
$temp = array(
array('id' => 5273, 'parent' => 0, 'name' => 'John Doe'),
array('id' => 6032, 'parent' => 5273, 'name' => 'Sally Smith'),
array('id' => 6034, 'parent' => 6032, 'name' => 'Mike Jones'),
array('id' => 6035, 'parent' => 6034, 'name' => 'Jason Williams'),
array('id' => 6036, 'parent' => 5273, 'name' => 'Sara Johnson'),
array('id' => 6037, 'parent' => 5273, 'name' => 'Dave Wilson'),
array('id' => 6038, 'parent' => 6037, 'name' => 'Amy Martin')
);
function getBreadcrumbsArray($temp)
{
foreach ($temp as $item) {
$temp_i[$item['id']] = array(
'parent' => $item['parent'],
'name' => $item['name'],
);
}
foreach ($temp as $item) {
$breadcrumbs[] = array(
'id' => $item['id'],
'name' => implode(' -> ', getBreadcrumbs($temp_i, $item['id']))
);
}
return $breadcrumbs;
}
function getBreadcrumbs($data_array, $id, $breadcrumbs = array())
{
$breadcrumbs[] = $data_array[$id]['name'];
if( $data_array[$id]['parent'] == 0 )
{
return array_reverse($breadcrumbs);
}
else
{
return getBreadcrumbs($data_array, $data_array[$id]['parent'], $breadcrumbs);
}
}
$breadcrumbs = getBreadcrumbsArray($temp);
print_r($breadcrumbs);
?>