I am using PHP. I need to implement the following logic:
My $List
has the following data:
array('id' =>'1','flag'=>'1','place1' =>'val2' ,'place2'=>'val3')
array('id'=> '1','flag'=>'0','place1' =>'val3' ,'place2'=>'val7')
array('id'=> '1','flag'=>'0','place1' =>'val4' ,'place2'=>'val8')
array('id'=> '1','flag'=>'0','place1' =>'val5' ,'place2'=>'val9')
array('id'=> '2','flag'=>'1','place1' =>'val10','place2'=>'val11')
array('id'=> '3','flag'=>'1','place1' =>'val11','place2'=>'val14')
My logic:
if (flag == 0){
Store the values of place1 ,Place2
in the Index of id
/*example
$store[1]= {place1}+{place2}
hence output:
store[1]= {val3+val4+val5}+{val7+val8+val9}
similarly
store[2]= empty
store[3]= empty
*/
}
else{
Print the Values of place1,place2 of its index
/* example
print place1[1]="val2" ,place2[1]='val3'
place1[2]="val10",place2[2]='val11'
place1[3]="val11",place2[3]='val14'
*/
}
My partial snippet has:
foreach ($List as $key => $val)
{
if($val['flag']!==0){
//how to implementation
}
else{
echo '$val['place1']'.'$val['place2']';
}
}
What is the best way to proceed?