嗨,伙計,合并這些陣列后我有 3 個陣列我得到了這個結果
這是我用于合并陣列的函式
function mergeArrays(...$arrays)
{
$length = count($arrays[0]);
$result = [];
for ($i=0;$i<$length;$i )
{
$temp = [];
foreach ($arrays as $array)
$temp[] = $array[$i];
$result[] = $temp;
}
return $result;
}
$mg = mergeArrays($serviceName, $quantite, $prix);
這是mpdf里面的php
<table style="width:100%;">
<thead>
<tr style="background-color: gray;">
<th style="text-align:center;">SERVICE</th>
<th style="text-align:center;">UNITE</th>
<th style="text-align:center;">PRIX</th>
</tr>
<thead>
<tr>
';
for ($i = 0; $i < count($mg); $i )
for($j = 0; $j < count($mg); $j ):
$html .='
<td>'.$mg[$i][$j].'</td>';
endfor;
$html.=
'
</tr>
</table>
輸出 在此處輸入影像描述
我想在每 3 列資料之后創建一個新行。感謝你們對我的幫助
uj5u.com熱心網友回復:
看起來您只是缺少<tr>外for回圈中的開頭和結尾。您可以像這樣添加標簽:
for ($i = 0; $i < count($mg); $i ) {
$html .= '<tr>'; //open row
for($j = 0; $j < count($mg); $j ) {
$html .='<td>'.$mg[$i][$j].'</td>';
}
$html .= '</tr>'; //close row
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454716.html
上一篇:獲取帖子的所有類別,用逗號分隔
