Oftentimes I come across code that looks like this: <?php
foreach($items as $item) {
doSomething($item["price"], $item["quantity"]);
}
// Or even
foreach($items as $index => $item) {
$basket[$index][] = [
$item['price'],
$item['quantity'],
];
} And there is an easy way to make your code look a little better using destructuring inside the for each loop <?php
foreach($items as ['price' => $price, 'quantity' => $quantity]) {
doSomething($price, $quantity);
}
foreach($items as $index => ['price' => $price, 'quantity' => $quantity]) {
$basket[$index][] = [ $price, $quantity ];
}