arrays
One type serves as list , dictionary , and set That flexibility is convenient and occasionally dangerous
indexed
$ports = [22, 80, 443];
$ports[] = 8080;
array_pop($ports);
array_shift($ports);
[] appends
array_pop removes from the end
array_shift removes from the start and reindexes
associative
$map = ["host" => "local", "port" => 443];
echo $map["port"];
Output:
443
Use array_key_exists when a key may hold null
isset returns false for a null value even when the key exists
Checking
count($ports);
array_key_exists("missing", $map);
Both were run No guessed return values in this chapter
Next
Strings in 04 strings
Posted