How can PHP arrays be used to simulate real-world scenarios, such as a shopping cart or inventory system?

PHP arrays can be used to simulate real-world scenarios by storing data in a structured format. For example, in a shopping cart scenario, you can use an array to store the items a user has added to their cart along with their quantities. Similarly, in an inventory system, you can use arrays to keep track of the available quantity of each product. By leveraging PHP arrays, you can easily manipulate and retrieve data, making it a versatile tool for simulating real-world scenarios.

// Shopping Cart Example
$cart = [
    ['id' => 1, 'product' => 'T-shirt', 'price' => 20, 'quantity' => 2],
    ['id' => 2, 'product' => 'Jeans', 'price' => 50, 'quantity' => 1]
];

// Inventory System Example
$inventory = [
    ['id' => 1, 'product' => 'T-shirt', 'quantity' => 50],
    ['id' => 2, 'product' => 'Jeans', 'quantity' => 20]
];