I have an set of array from my sql query
Array
(
[0] => stdClass Object
(
[id] => 1
[DSR] => 1016130
[aplan] => $90-Standard
[plan] => $44-Standard
[cli] => 089561287
[mobile] => 0428333999
)
Now this is displaying in a single row but I am trying to split it in two rows by key [aplan] and [plan].
Current output
1|1016130|$90-Standard|$44-Standard|089561287|0428333999
Desire out will be
1|1016130|$90-Standard|089561287|0428333999
2|1016130|$44-Standard|089561287|0428333999
Will appreciate the help.
lets say your 0 index is $arr
. Notice that you have the same id, so the first value of output should be 1. If you want as 1, 2.. Then need some furnish..
$plan = array();
$aplan = array();
foreach($arr as $key => $value){
if($key == 'aplan' || $key == 'plan'){
if($key == 'aplan')
$aplan[] = $value;
else
$plan[] = $value;
}
else{
$plan[] = $value;
$aplan[] = $value;
}
}
echo implode("|", $aplan); // 1|1016130|$90-Standard|089561287|0428333999
echo implode("|", $plan); // 1|1016130|$44-Standard|089561287|0428333999
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.