I am generating an array from a while loop, and I would like to eventually use this array to display data.
while($row = $database->fetch(PDO::FETCH_ASSOC)
{
$value_1 = $row['value_1'];
$value_2 = $row['value_2'];
$data[] = array("value_1"=>$value_1,"value_2"=>$value_2);
}
so the $data[] would display using print_r I get something like this:
Array
(
[0] => Array
(
[value_1] => Hello World
[value_2] => venus
)
[1] => Array
(
[value_1] => Hello World
[value_2] => pluto
)
[2] => Array
(
[value_1] => Hello Moon
[value_2] => Halloween
)
)
My question is, how would I do a foreach loop or display such a way where if I wanted to get all data, but consolidate the same values?
Ex:
Hello World to venus pluto
Hello Moon to Halloween
I know those sentences doesn't make sense, but as you can see Hello World would be consolidated and I would need to add an " to" in between value_1 and value_2
Hope my question is understandable.
Thanks!