如何让 PHP 回显表中的数据

问题描述 投票:0回答:1

**当前代码:**

  // Display flight details
            echo "<h2>Flight Details</h2>";
            echo "Aircraft Name: $aircraft_name<br>";
            echo "Arrival Country: $arrival_country<br>";
            echo "Scheduled Arrival Time: $scheduled_arrival<br>";
            echo "Actual Arrival Time: $arrival_actual<br>";
            echo "Departure Country: $departure_country<br>";
            echo "Scheduled Departure Time: $scheduled_departure<br>";
            echo "Actual Departure Time: $departure_actual<br>";
            echo "Flight Status: $flight_status<br>";

        } else {
            echo "Flight not found or API error.";
        }
    }
    ?>

期望格式:

enter image description here

感谢您的帮助。预先感谢

我正在寻找表格格式

php echo
1个回答
0
投票
$data = [
    "Aircraft Name" => "N/A", // Use variable: $aircraft_name
    "Arrival Country: " => "Chennai", // Use variable: $arrival_country
    "Scheduled Arrival Time" => "2023-09-04", // Use variable: $scheduled_arrival
    "Actual Arrival Time" => "2023-09-04", // Use variable: $arrival_actual
    "Departure Country" => "Dubai", // Use variable: $departure_country
    "Scheduled Departure Time" => "2023-09-04", // Use variable: $scheduled_departure
    "Actual Departure Time" => "2023-09-04", // Use variable: $departure_actual
    "Flight Status" => "Arrived", // Use variable: $flight_status
];

echo "<table border=1>";
echo "<tbody>";

// First row, 2 columns: 1st column is "blank" and 2nd column is "Flight Details"
echo "<tr>";
echo "<td></td>";
echo "<td>Flight Details</td>";
echo "</tr>";

// Iterate the data using foreach instead of writing too many echo statements
foreach ($data as $key => $value) {
    echo "<tr>";
    echo "<td style= \"background-color:#114882; color:#fff;\">{$key} :</td>";
    echo "<td>{$value}</td>";
    echo "</tr>";
}

echo "</tbody>";
echo "</table>";
© www.soinside.com 2019 - 2024. All rights reserved.