Home > Article > Backend Development > PHP Learning Array Value Operations_PHP Tutorial
1. Extraction of values
In PHP, list is used to extract the values in the array, such as list($a, $b) = $array. If there are more values in the list than the number of arrays, the excess values in the list will be set to NULL. You can also use commas to skip values in the array, such as list($a, ,$b) = $array.
2. Divide the array
If you want to get the sub-array, you can use array_slice(array, offset, length); to get it. It returns a new array with indexes starting from 0. If the subscript of the original array is a string, it seems to be meaningless, so it is best not to use it. You can use array_splice to obtain the substring.
3. Divide the array into multiple arrays
Use array_chunk to divide the array into a two-dimensional array. For details, you can read the official instructions through the link.
4. Keys and values
array_keys($array), get the array composed of array index
array_value($array), get the array composed of array value, the index is from 0 Start reallocation.
array_key_exists($key, array), check whether the element exists.
array_splice, delete inserted elements.
5. Conversion between arrays and variables
extract(array) turns arrays into variables
compact() turns variables into arrays