PHP - 正确显示MySQL的结果

时间:2016-11-14 16:49:09

标签: php mysql

我只是想知道是否有办法显示这一个而不是第一个数量而不是日期。

$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>';}?>

此代码将显示:

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

我需要的是:

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

我从MySQL获得了值。

2 个答案:

答案 0 :(得分:1)

我认为你可以这样做,但我不确定这是更好的方式

foreach($apaidArray as $key_array => $apaid_Array)
{
    echo trim($apaid_Array,",").' '.trim($daterArray[$key_array],",") .'</br>';
}

输出:

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

而不是

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

你可以直接做

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

而不是

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

答案 1 :(得分:1)

同时走两个阵列:

<?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>';
}
?>

结果是:

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