Creates an array. Read the section on the array type for more information on what an array is.
Parameters
values
Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical index are defined, the last overwrite the first.
Having a trailing comma after the last defined array entry, while unusual, is a valid syntax.
Return Values
Returns an array of the parameters. The parameters can be given an index with the
=>
operator. Read the section on the array type for more information on what an array is.
Examples
The following example demonstrates how to create a two-dimensional array, how to specify keys for associative arrays, and how to skip-and-continue numeric indices in normal arrays.
Note that index '3' is defined twice, and keep its final value of 13. Index 4 is defined after index 8, and next generated index (value 19) is 9, since biggest index was 8.
If an array has indices that will be the same once run through this function (e.g. "
keY
" and "
kEY
"), the value that is later in the array will override other indices.
Chunks an array into arrays with
length
elements. The last chunk may contain less than
length
elements.
Parameters
array
The array to work on
length
The size of each chunk
preserve_keys
When set to
true
keys will be preserved. Default is
false
which will reindex the chunk numerically
Return Values
Returns a multidimensional numerically indexed array, starting with zero, with each dimension containing
length
elements.
Errors/Exceptions
If
length
is less than
1
, a
ValueError
will be thrown.
Changelog
Version
Description
8.0.0
If
length
is less than
1
, a
ValueError
will be thrown now; previously, an error of level
E_WARNING
has been raised instead, and the function returned
null
.