An indexed array has the keys 0, 1, 2..., an associative array uses string keys, and a nested array holds arrays, as an order holds its line items. $a[] = $v appends with the largest integer key plus one. Keys are ints or strings: "7" becomes 7 ("07" stays a string), true becomes 1, and a float is truncated, with a deprecation since PHP 8.1 if a fraction is lost.
<?php
$order = ['id' => 5001, 'customer' => ['name' => 'Ann Lee', 'city' => 'Leeds'],
'items' => [['sku' => 'BK-101', 'qty' => 2]]]; // nested: arrays inside arrays
$order['items'][] = ['sku' => 'BK-300', 'qty' => 4]; // append to the inner list
echo $order['customer']['city'], ' ', $order['items'][1]['sku'], "\n";
$k = ['7' => 'a', '07' => 'b', true => 'c', -5 => 'd']; // key casting
$k[] = 'e'; // largest int key + 1
echo json_encode(array_keys($k)), "\n";
$opts = ['per_page' => 50] + ['currency' => 'USD', 'per_page' => 20]; // left side wins
echo json_encode([$opts, ['a' => 1, 'b' => 2] == ['b' => 2, 'a' => 1],
['a' => 1, 'b' => 2] === ['b' => 2, 'a' => 1], array_is_list([1 => 'x'])]), "\n";Output
Leeds BK-300
[7,"07",1,-5,8]
[{"per_page":50,"currency":"USD"},true,false,false]+ is a key-wise union keeping the left value on a clash, the idiom for defaults. === also demands the same order and types. array_is_list() (PHP 8.1) checks for keys 0 to n-1, which is what makes json_encode() emit a JSON array.
