The Arrays class for PHP's array manipulation
Namespace: Sphp \ Stdlib
PHP's array type can be treated as
an array, list (vector), hash table (an implementation of a map), dictionary,
collection, stack, queue, and much more. As values can be other arrays,
trees and multidimensional arrays are also possible.[1]
Arrays is an utility class for dealing with arrays and nested arrays in PHP. It contains static methods that extend PHP's core array related operations.
Arrays has methods for:
testing array properties.
manipulating array properties and creating new arrays.
'cloning' multidimensional PHP arrays.
Synopsis
Returns the next key after the current array position
public static getNextKey ( array $array ,
string|int $key ) : string|int|null
Returns the previous key from the current array position
public static getPreviousKey ( array $array ,
string|int $key ) : string|int|null
Sets the internal array pointer to the given key value pair
public static pointToKey ( array $array ,
string|int $key ) : void
Sets the internal array pointer to the given key value pair
public static pointToValue ( array $array ,
mixed $value ) : void
Checks whether a value exists in the array
public static inArray ( mixed $needle ,
array $haystack ) : bool
public static filterRecursive ( array $array ,
?callable $callback = null ,
bool $removeEmptyArrays = true ) : array
Search an array for string values that contain the given phrase
public static getValuesLike ( array $arr ,
string $needle ) : array
Search a single dimensional array for keys that contain the given phrase
public static findKeysLike ( array $arr ,
$needle ) : array
Checks if each key is an integer value
public static isIndexed ( array $arr ) : bool
Checks if each key is an integer value and if all keys are in sequential
order starting at $base
public static isSequential ( array $arr ,
?int $base = null ) : bool
Returns the input array values in a sequential array
public static setSequential ( array $arr ,
int $base = 0 ) : array
Implode an array with the key and value pair giving a glue, a separator
between pairs and the array to implode.
public static implodeWithKeys ( array $array ,
$separator = ', ' ,
$glue = ' => ' ) : string
Checks if the array is multidimensional or not
public static isMultidimensional ( array $array ) : bool
Implodes all elements of an (optionally multidimensional) array with a string
public static recursiveImplode ( array $arr ,
string $glue = '' ) : string
Joins a string with a natural language conjunction at the end.
public static naturalLanguageJoin ( array $list ,
Stringable |string $conjunction = 'and') : string
Executes a recursive search to an input array
public static recursiveFind ( array $haystack ,
mixed $needle ) : mixed
Copies all the values of an array to a result array
public static copy ( array $arr ) : array
Returns the values of an input array in a single dimension array
public static flatten ( array $array ) : array
References