阵列填充空间

时间:2017-10-01 05:55:36

标签: php arrays

我有一个数组

Array (
[0] => 1500 
[1] => 2000
[2] => - )

Array ( 
[0] => 1 
[1] => 2 
[2] => 3 ) 

Array ( 
[0] => 
[1] => - 
[2] => - )      

尝试了这段代码,但它对我不起作用

$default = array_fill(0,3,'-');
$paymentexplode = array_replace($default, explode(",",$CARDNUMBER_PAYMENT_MX));
$explodedeductedfinal = array_replace($default, explode(",",$PAYMENT_AMOUNT_MX));

用于输出td

中的数据
foreach($explodedeductedfinal as $is){
    $bankname = trim($is);

    if (!empty($bankname)) {
        echo   "<td class='center'>$bankname</td>";
    }
}

它只给了我这个系列:

CODE1|  CODE2  |CODE3
1500    2000      -
1       2         3
-       -

应该是这个

CODE1|  CODE2  |CODE3
1500    2000      -
1       2         3
-       -         -

1 个答案:

答案 0 :(得分:0)

如果你有一个空单元格,你仍然需要输出<td>,否则你会得到一个不平衡的表格。

foreach($explodedeductedfinal as $is){
    $bankname = trim($is);

    echo "<td class='center'>";
    if (!empty($bankname)) {
        echo   $bankname;
    }
    echo "</td>";
}