PHP 在 HTML 表格中显示关联数组

Kas*_*eed 3 html php associative-array

这是我的关联数组:

$req_data1[]=array(
    'depart1'=>$_REQUEST['to'],
    'd_time1'=>$d_time5,
    'stop'=>"",
    'leave_stop'=>"",
    'arrival1'=>$_REQUEST['from'],
    'a_time1'=>$end_time5,
    'price1'=>intval($final_price),
    'air_line'=>"xxxxx");
Run Code Online (Sandbox Code Playgroud)

这是我的排序算法:

foreach ($req_data as $key => $row) {
    $depart[$key]  = $row['depart'];
    $d_time[$key] = $row['d_time'];
    $stop[$key]  = $row['stop'];
    $leave_stop[$key] = $row['leave_stop'];
    $arrival[$key]  = $row['arrival'];
    $a_time[$key] = $row['a_time'];
    $price[$key] = $row['price'];
}

array_multisort($price,SORT_ASC, $req_data);
Run Code Online (Sandbox Code Playgroud)

我在排序后显示数据:

foreach($req_data as $key=>$row) {
    echo "</br>";

    foreach($row as $key2=>$row2){
        echo $row2;
    }
}
Run Code Online (Sandbox Code Playgroud)

我现在的问题是我想将该数组放入 HTML 表中,但不知道如何操作。这是我到目前为止尝试过的代码,但它不起作用:

$cols = 5; 

echo "<table border=\"5\" cellpadding=\"10\">"; 

for ($r=0; $r < count($row2); $r++) { 
    echo "<tr>"; 

    for ($c=0; $c<$cols; $c++) { 

        ?> <td> <?php $input[$r+$c] ?> </td> <?php 
        }

    echo "</tr>"; 
    $r += $c; 
}

echo "</table>";
?>
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我的代码有什么问题,或者我如何将这些排序的数据显示到表格中?谢谢。

Dan*_*man 5

为什么不修改您已经用于显示数据的循环?

echo "<table>";
foreach($req_data as $key=>$row) {
    echo "<tr>";
    foreach($row as $key2=>$row2){
        echo "<td>" . $row2 . "</td>";
    }
    echo "</tr>";
}
echo "</table>";
Run Code Online (Sandbox Code Playgroud)