Strings and arrays have become a practical tool for processing data in unconditional relationships. To form an array by a string, execute processing and write back to a string is practical, quick and understandable. Without cycles, conditions and complex algorithms.
Dynamic array usage
The attitude to the array as a data set associated with an ordered sequence of digits - keys, is outdated. This array option is used universally for simple data sets.
Associative array: instead of a sequence of digital keys, a character string is used - a standard for unconditional relationships outside a relational database.
PHP functions allow you to swap keys and values, convert arrays to strings and vice versa. This creates the foundation for dynamic arrays.
The PHP array_keys () function allows you to select only key information. Using a function is relevant on many associative and regular arrays. The application logic is determined by the programmer.
Relational relationships are relationships of equality between data. In fact, that key is that value is one and the same. "Key" = "Value" - an element of an associative array. If the key is an ordered sequence of numbers, then in some cases it is no worse than an ordered sequence of lines that make sense.
A simple example. Array of characters (in this case: numbers and six letters):
- '0' .. '9', 'a', 'b', 'c', 'd', 'e', 'f' - values;
- 0..15 - keys.
Such an array will allow you to write a simple code to convert numbers from decimal to hexadecimal.
Key usage examples
Programming is filled with semantics. Yesterday there was an array of data. Today it is customary to talk about a set of values. Two equivalent arrays are two sets of values. The sequence of such arrays is the dynamics of relations in time.
Thanks to the array_keys () function, you can know what data (and how it is named) changes over time. By changing the key = "value" pairs in places with the array_flip () function, you can get, for example, the rating of keys.
Equality relationships are the foundation of relational relationships that are commonly used in programming.
An additional feature of PHP: array_keys () has a second argument, using which you can select keys by strict criteria.
By manipulating keys and values as pairs of unconditional correspondence, you can build effective information processing algorithms.