Unit 02 of 03
Arrays and Strings
A single ordered map used as both list and dictionary, key normalization, missing keys in nested arrays, how array functions report what they cannot find, and string handling working over bytes.
Published Updated
Lessons
- 01 Indexed and Associative Arrays One array structure used as both a list and a dictionary; the keys '1', 1 and true collapsing into a single key; a decimal key being truncated; normalization applying only to canonical decimal integer strings. 2 min read
- 02 Multidimensional Arrays Nesting arrays inside arrays; a missing inner key giving null with an E_WARNING; array access on null; the null coalescing operator silencing the whole path; reading and writing being separate channels. 1 min read
- 03 Array Functions The filter, map and reduce functions; array_search returning false when it finds nothing; a match at index zero being confused with false in a loose comparison; array_combine with mismatched lengths and a negative str_repeat call throwing ValueError. 1 min read
- 04 String Handling Formatting with sprintf and printf; the byte and character distinction between strlen and mb_strlen; malformed JSON coming back from json_decode as null; telling the cases apart with json_last_error and JSON_THROW_ON_ERROR; the behavior of implode and strlen on an array argument. 1 min read