Cluster Cluster - 23 days ago 7
PHP Question

PHP - Disply results from MySQL correctly

I was just wondering if there is a way to display this one after the other rather than first amounts than dates.

$apaidString = $apaid;
$daterString = $dater;
$apaidArray = explode(',', $apaidString);
$daterArray = explode(',', $daterString);

<?php foreach($apaidArray as $apaid_Array){
echo trim($apaid_Array,",").'<br>';}?>
<?php foreach($daterArray as $dater_Array){
echo trim($dater_Array,",").'<br>';}?>


This code will display:

50
60
10
11-11-2016
12-11-2016
14-11-2016


What i would need would be:

50 11-11-2016
60 12-11-2016
10 14-11-2016


I get the values from a MySQL. Any help is greatly appreciated.

Answer

Walk both arrays at the same time :

<?php
$apaidString = "50,60,10";
$daterString = "11-11-2016,12-11-2016,14-11-2016";
$apaidArray = explode(',', $apaidString);
$daterArray = explode(',', $daterString);

for ( $i = 0; $i < count($apaidArray); $i++ )
{ echo $apaidArray[$i].'<br>';
  echo $daterArray[$i].'<br>';
}
?>

The result is:

50
11-11-2016
60
12-11-2016
10
14-11-2016