this is example of my data
name month
abc Jan
xyz Jan
efg feb
ijk apr
mno apr
question is, how to group, using while loop, so the result like this
Jan
abc
xyz
feb
efg
apr
ijk
mno
this is example of my data
name month
abc Jan
xyz Jan
efg feb
ijk apr
mno apr
question is, how to group, using while loop, so the result like this
Jan
abc
xyz
feb
efg
apr
ijk
mno
I've used a foreach loop instead, but something like the following should work.
$month = null;
foreach($data as $row)
{
if(is_null($month) || $month <> $row['month']) {
$month = $row['month'];
echo "<strong>{$month}</strong><br />";
}
echo "{$row['name']}<br />";
}
Thanks.. But im trying to get the answer using while loop
I suggested a foreach
loop because it removes the complexity.
It's more complicated with a while loop. You'll need to look into the use of the current
, next
and perhaps end
functions for arrays.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.