we have an array like this :
Array
(
[0] => Array
(
[value] => aaa
[parent_id] => 5
)
[1] => Array
(
[value] => bbb
[parent_id] => 3
)
[2] => Array
(
[value] => ccc
[parent_id] => 3
)
)
as you can see 2 index have same [parent_id] , we need convert this array to this
Array
(
[0] => Array
(
[parent_id] => 5
[sub] => Array(
[0] =>(
[value] => aaa
)
)
)
[1] => Array
(
[parent_id] => 3
[sub] => Array(
[0] =>(
[value] => bbb
)
[1] =>(
[value] => ccc
)
)
)
)
in php we used this functions :
foreach ($Array as $item) {
$item['subs'] = array();
$indexedItems[$item['parent_id']] = (object) $item;
}
for($i=0; $i<count($Array); $i++){
if($Array[$i]['parent_id'] == $Array[$i-1]['parent_id']){
$indexedItems[$item['parent_id']]->subs[]=$Array[$i]['value'];
}
}
but it doesnot works , can you help us to do that , please ?