How can PHP be used to efficiently compare planned versus actual work hours in a table format?
To efficiently compare planned versus actual work hours in a table format using PHP, you can create an array or fetch data from a database containing the planned and actual work hours for each task. Then, loop through the data and compare the values to determine if the actual work hours match the planned work hours. Finally, display the results in a table format for easy comparison.
// Sample data containing planned and actual work hours for tasks
$work_hours = [
['task' => 'Task 1', 'planned_hours' => 8, 'actual_hours' => 6],
['task' => 'Task 2', 'planned_hours' => 4, 'actual_hours' => 4],
['task' => 'Task 3', 'planned_hours' => 6, 'actual_hours' => 8],
];
// Display table header
echo "<table border='1'>";
echo "<tr><th>Task</th><th>Planned Hours</th><th>Actual Hours</th><th>Comparison</th></tr>";
// Loop through the data and compare planned vs actual work hours
foreach ($work_hours as $task) {
echo "<tr>";
echo "<td>{$task['task']}</td>";
echo "<td>{$task['planned_hours']}</td>";
echo "<td>{$task['actual_hours']}</td>";
// Compare planned vs actual work hours
if ($task['planned_hours'] == $task['actual_hours']) {
echo "<td>Match</td>";
} else {
echo "<td>Mismatch</td>";
}
echo "</tr>";
}
echo "</table>";