How can you use an associative array in PHP to match IDs from one table with values in another table?

When you have two tables with related data, you can use an associative array in PHP to match IDs from one table with values in another table. You can create an associative array where the keys are the IDs from the first table and the values are the corresponding values from the second table. This allows you to easily access the related values based on the ID.

// Assuming $table1 and $table2 are arrays representing the two tables
// Create an associative array to match IDs from $table1 with values from $table2
$matchedData = [];
foreach ($table1 as $row) {
    $matchedData[$row['id']] = $table2[$row['id']]['value'];
}

// Access the matched values using the IDs from $table1
foreach ($matchedData as $id => $value) {
    echo "ID: $id, Value: $value\n";
}