How can the values of different criteria, such as $manufacturer and $product_attributes, be effectively utilized in a foreach loop in PHP?
When utilizing the values of different criteria like $manufacturer and $product_attributes in a foreach loop in PHP, you can create an associative array where each key represents a specific manufacturer and the corresponding value is an array of product attributes. This way, you can easily access and manipulate the data within the loop.
// Sample data for demonstration
$manufacturer = ['Apple', 'Samsung', 'Google'];
$product_attributes = [
'Apple' => ['iPhone', 'iPad', 'MacBook'],
'Samsung' => ['Galaxy', 'Note', 'Tab'],
'Google' => ['Pixel', 'Nexus', 'Chromebook']
];
// Utilizing the values in a foreach loop
foreach ($manufacturer as $manu) {
echo "Manufacturer: $manu\n";
echo "Products: ";
foreach ($product_attributes[$manu] as $product) {
echo "$product, ";
}
echo "\n\n";
}