PHP learns the operation of array values

  • 2020-03-31 21:36:55
  • OfStack

1. Value disjunction
In PHP, use the list to extract the values in the array, such as (link: http://php.net/manual/en/function.list.php) ($a, $b) = $array. If there are more values in the list than in the array, the extra values in the list are set to NULL. You can also skip values in an array with a comma, such as list($a, $b) = $array.

2. Divide the array
If you want to achieve subarray, can use (link: http://php.net/manual/en/function.array-slice.php) (array, offset, length); To achieve. It returns an array with a new index starting at 0. If the original array subscript is a string, it seems there is no meaning, it is best not to use, can use the substring (link: http://www.php.net/manual/en/function.array-splice.php).

Divide the array into multiple arrays
Use (link: http://www.php.net/manual/en/function.array-chunk.php) can put an array into a two dimensional array. Details can be seen through the link to the official instructions.

4. The keys and values
(link: http://www.php.net/manual/en/function.array-keys.php) ($array), obtained by the array index of an array
(link: http://www.php.net/manual/en/function.array-values.php) ($array), obtained by an array of values of an array, the index starting from 0.
(link: http://www.php.net/manual/en/function.array-key-exists.php) ($key, array), element exists.
(link: http://www.php.net/manual/en/function.array-splice.php), delete the inserted element.

5. Conversion between arrays and variables
(link: http://www.php.net/manual/en/function.extract.php) (array) array into a variable
(link: http://www.php.net/manual/en/function.compact.php) (the) variable into an array


Related articles: