How can arrays be used in PHP to store items and their corresponding prices?
To store items and their corresponding prices in PHP, you can use an associative array where the item names are the keys and the prices are the values. This allows you to easily access the price of an item by referencing its name in the array.
// Create an associative array to store items and their prices
$items = [
'apple' => 0.99,
'banana' => 0.59,
'orange' => 0.79
];
// Access the price of an item
echo 'The price of an apple is $' . $items['apple'];
Related Questions
- Are there any specific MIME types or headers that need to be set when sending XFDF files via email in PHP?
- What are the best practices for handling variations in text entries, such as different spellings of "iPhone5" in PHP?
- What are some common pitfalls when using setcookie in PHP, especially within a switch case statement?