class ArrayHelper

Class ArrayHelper

Methods

static bool
accessible(mixed $value)

Determine whether the given value is array accessible.

static bool
isAssoc(array $array)

Determines if an array is associative.

static Traversable
toIterator(mixed $array)

No description

static mixed
toObject(array|Traversable $array, string $class = \stdClass::class)

array data to object

static array
gets(array $data, array $needKeys = [], bool|false $unsetKey = false)

Get Multi - 获取多个, 可以设置默认值

static array
merge(array|null $src, array $new)

递归合并两个多维数组,后面的值将会递归覆盖原来的值

static array
merge2(array ...$args)

递归合并多个多维数组,

static array|string
valueTrim(array $data)

清理数组值的空白

static bool
keyExists(int|string $key, array $arr)

不区分大小写检测数据键名是否存在

static array
valueToLower(array $arr)

No description

static array
valueToUpper(array $arr)

No description

static array
changeValueCase(array $arr, int $toUpper = 1)

将数组中的值全部转为大写或小写

static bool
valueExistsAll(string|array $check, array $sampleArr)

******* 检查 一个或多个值是否全部存在数组中 ******* 有一个不存在即返回 false

static bool
valueExistsOne(string|array $check, array $sampleArr)

******* 检查 一个或多个值是否存在数组中 ******* 有一个存在就返回 true 都不存在 return false

static bool
existsAll(string|array $need, array $arr, bool $type = false)

******* 不区分大小写,检查 一个或多个值是否 全存在数组中 ******* 有一个不存在即返回 false

static bool
existsOne(string|array $need, array $arr, bool $type = false)

******* 不区分大小写,检查 一个或多个值是否存在数组中 ******* 有一个存在就返回 true 都不存在 return false

static int
getKeyMaxWidth(array $data, bool $expectInt = true)

get key Max Width

static mixed
getByPath(array|ArrayAccess $data, string $path, mixed $default = null, string $separator = '.')

Get data from array or object by path.

static 
setByPath(array|ArrayAccess $data, string $path, mixed $value, string $separator = '.')

setByPath

static array
collapse(array $array)

Collapse an array of arrays into a single array.

static array
crossJoin(array ...$arrays)

Cross join the given arrays, returning all possible permutations.

static array
divide(array $array)

Divide an array into two arrays. One with keys and the other with values.

static array
dot(array $array, string $prepend = '')

Flatten a multi-dimensional associative array with dots.

static array
except(array $array, array|string $keys)

Get all of the given array except for a specified array of items.

static bool
exists(ArrayAccess|array $array, string|int $key)

Determine if the given key exists in the provided array.

static array
add(array $array, string $key, mixed $value)

Add an element to an array using "dot" notation if it doesn't exist.

static mixed
get(ArrayAccess|array $array, string $key, mixed $default = null)

Get an item from an array using "dot" notation.

static array
set(array $array, string $key, mixed $value)

Set an array item to a given value using "dot" notation.

static array
flatten(array $array, int $depth = INF)

Flatten a multi-dimensional array into a single level.

static void
forget(array $array, array|string $keys)

Remove one or many array items from a given array using "dot" notation.

static bool
has(ArrayAccess|array $array, string|array $keys)

Check if an item or items exist in an array using "dot" notation.

static array
prepend(array $array, mixed $value, mixed $key = null)

Push an item onto the beginning of an array.

static mixed
remove($arr, $key, $default = null)

remove the $key of the $arr, and return value.

static mixed
pull(array $array, string $key, mixed $default = null)

Get a value from the array, and remove it.

static array
only(array $array, array|string $keys)

Get a subset of the items from the given array.

static array
shuffle(array $array)

Shuffle the given array and return the result.

static array
where(array $array, callable $callback)

Filter the array using the given callback.

static array
wrap(mixed $value)

If the given value is not an array, wrap it in one.

static string
toString(array $array, int $length = 800, array|int $cycles = 6, bool $showKey = true, bool $addMark = false, string $separator = ', ', string $string = '')

array 递归 转换成 字符串

static 
toStringNoKey($array, $length = 800, $cycles = 6, $showKey = false, $addMark = true, $separator = ', ')

No description

static mixed|null|string|string[]
toFormatString(array $array, int $length = 400)

No description

static 
toLimitOut($array)

No description

Details

at line 25
static bool accessible(mixed $value)

Determine whether the given value is array accessible.

Parameters

mixed $value

Return Value

bool

at line 36
static bool isAssoc(array $array)

Determines if an array is associative.

An array is "associative" if it doesn't have sequential numerical keys beginning with zero.

Parameters

array $array

Return Value

bool

at line 47
static Traversable toIterator(mixed $array)

Parameters

mixed $array

Return Value

Traversable

at line 62
static mixed toObject(array|Traversable $array, string $class = \stdClass::class)

array data to object

Parameters

array|Traversable $array
string $class

Return Value

mixed

at line 91
static array gets(array $data, array $needKeys = [], bool|false $unsetKey = false)

Get Multi - 获取多个, 可以设置默认值

Parameters

array $data array data
array $needKeys $needKeys = [ 'name', 'password', 'status' => '1' ]
bool|false $unsetKey

Return Value

array

at line 131
static array merge(array|null $src, array $new)

递归合并两个多维数组,后面的值将会递归覆盖原来的值

Parameters

array|null $src
array $new

Return Value

array

at line 165
static array merge2(array ...$args)

递归合并多个多维数组,

Parameters

array ...$args

Return Value

array the merged array (the original arrays are not changed.)

at line 197
static array|string valueTrim(array $data)

清理数组值的空白

Parameters

array $data

Return Value

array|string

at line 216
static bool keyExists(int|string $key, array $arr)

不区分大小写检测数据键名是否存在

Parameters

int|string $key
array $arr

Return Value

bool

at line 225
static array valueToLower(array $arr)

Parameters

array $arr

Return Value

array

at line 234
static array valueToUpper(array $arr)

Parameters

array $arr

Return Value

array

at line 245
static array changeValueCase(array $arr, int $toUpper = 1)

将数组中的值全部转为大写或小写

Parameters

array $arr
int $toUpper 1 值大写 0 值小写

Return Value

array

at line 270
static bool valueExistsAll(string|array $check, array $sampleArr)

******* 检查 一个或多个值是否全部存在数组中 ******* 有一个不存在即返回 false

Parameters

string|array $check
array $sampleArr 只能检查一维数组 注: 不分类型, 区分大小写 2 == '2' ‘a' != 'A'

Return Value

bool

at line 288
static bool valueExistsOne(string|array $check, array $sampleArr)

******* 检查 一个或多个值是否存在数组中 ******* 有一个存在就返回 true 都不存在 return false

Parameters

string|array $check
array $sampleArr 只能检查一维数组

Return Value

bool

at line 307
static bool existsAll(string|array $need, array $arr, bool $type = false)

******* 不区分大小写,检查 一个或多个值是否 全存在数组中 ******* 有一个不存在即返回 false

Parameters

string|array $need
array $arr 只能检查一维数组
bool $type 是否同时验证类型

Return Value

bool | string 不存在的会返回 检查到的 字段,判断时 请使用 ArrHelper::existsAll($need,$arr)===true 来验证是否全存在

at line 341
static bool existsOne(string|array $need, array $arr, bool $type = false)

******* 不区分大小写,检查 一个或多个值是否存在数组中 ******* 有一个存在就返回 true 都不存在 return false

Parameters

string|array $need
array $arr 只能检查一维数组
bool $type 是否同时验证类型

Return Value

bool

at line 378
static int getKeyMaxWidth(array $data, bool $expectInt = true)

get key Max Width

Parameters

array $data [ 'key1' => 'value1', 'key2-test' => 'value2', ]
bool $expectInt

Return Value

int

at line 403
static mixed getByPath(array|ArrayAccess $data, string $path, mixed $default = null, string $separator = '.')

Get data from array or object by path.

Example: DataCollector::getByPath($array, 'foo.bar.yoo') equals to $array['foo']['bar']['yoo'].

Parameters

array|ArrayAccess $data An array or object to get value.
string $path The key path.
mixed $default
string $separator Separator of paths.

Return Value

mixed Found value, null if not exists.

at line 438
static setByPath(array|ArrayAccess $data, string $path, mixed $value, string $separator = '.')

setByPath

Parameters

array|ArrayAccess $data &$data
string $path
mixed $value
string $separator

at line 478
static array collapse(array $array)

Collapse an array of arrays into a single array.

Parameters

array $array

Return Value

array

at line 500
static array crossJoin(array ...$arrays)

Cross join the given arrays, returning all possible permutations.

Parameters

array ...$arrays

Return Value

array

at line 516
static array divide(array $array)

Divide an array into two arrays. One with keys and the other with values.

Parameters

array $array

Return Value

array

at line 527
static array dot(array $array, string $prepend = '')

Flatten a multi-dimensional associative array with dots.

Parameters

array $array
string $prepend

Return Value

array

at line 548
static array except(array $array, array|string $keys)

Get all of the given array except for a specified array of items.

Parameters

array $array
array|string $keys

Return Value

array

at line 561
static bool exists(ArrayAccess|array $array, string|int $key)

Determine if the given key exists in the provided array.

Parameters

ArrayAccess|array $array
string|int $key

Return Value

bool

at line 577
static array add(array $array, string $key, mixed $value)

Add an element to an array using "dot" notation if it doesn't exist.

Parameters

array $array
string $key
mixed $value

Return Value

array

at line 593
static mixed get(ArrayAccess|array $array, string $key, mixed $default = null)

Get an item from an array using "dot" notation.

Parameters

ArrayAccess|array $array
string $key
mixed $default

Return Value

mixed

at line 626
static array set(array $array, string $key, mixed $value)

Set an array item to a given value using "dot" notation.

If no key is given to the method, the entire array will be replaced.

Parameters

array $array
string $key
mixed $value

Return Value

array

at line 657
static array flatten(array $array, int $depth = INF)

Flatten a multi-dimensional array into a single level.

Parameters

array $array
int $depth

Return Value

array

at line 680
static void forget(array $array, array|string $keys)

Remove one or many array items from a given array using "dot" notation.

Parameters

array $array
array|string $keys

Return Value

void

at line 722
static bool has(ArrayAccess|array $array, string|array $keys)

Check if an item or items exist in an array using "dot" notation.

Parameters

ArrayAccess|array $array
string|array $keys

Return Value

bool

at line 765
static array prepend(array $array, mixed $value, mixed $key = null)

Push an item onto the beginning of an array.

Parameters

array $array
mixed $value
mixed $key

Return Value

array

at line 783
static mixed remove($arr, $key, $default = null)

remove the $key of the $arr, and return value.

Parameters

$arr
$key
$default

Return Value

mixed

at line 802
static mixed pull(array $array, string $key, mixed $default = null)

Get a value from the array, and remove it.

Parameters

array $array
string $key
mixed $default

Return Value

mixed

at line 817
static array only(array $array, array|string $keys)

Get a subset of the items from the given array.

Parameters

array $array
array|string $keys

Return Value

array

at line 827
static array shuffle(array $array)

Shuffle the given array and return the result.

Parameters

array $array

Return Value

array

at line 840
static array where(array $array, callable $callback)

Filter the array using the given callback.

Parameters

array $array
callable $callback

Return Value

array

at line 850
static array wrap(mixed $value)

If the given value is not an array, wrap it in one.

Parameters

mixed $value

Return Value

array

at line 870
static string toString(array $array, int $length = 800, array|int $cycles = 6, bool $showKey = true, bool $addMark = false, string $separator = ', ', string $string = '')

array 递归 转换成 字符串

Parameters

array $array [大于1200字符 strlen($string)>1200
int $length
array|int $cycles [至多循环六次 $num >= 6
bool $showKey
bool $addMark
string $separator
string $string

Return Value

string

at line 916
static toStringNoKey($array, $length = 800, $cycles = 6, $showKey = false, $addMark = true, $separator = ', ')

Parameters

$array
$length
$cycles
$showKey
$addMark
$separator

at line 932
static mixed|null|string|string[] toFormatString(array $array, int $length = 400)

Parameters

array $array
int $length

Return Value

mixed|null|string|string[]

at line 949
static toLimitOut($array)

Parameters

$array