timdev / php-array-utils
实用的PHP数组工具。
0.1.1
2016-02-04 02:54 UTC
Requires (Dev)
- phpunit/phpunit: ^5.1
This package is auto-updated.
Last update: 2024-09-20 05:09:19 UTC
README
每个人在编写大量的PHP代码时,最终都会编写一些用于执行常见数组操作任务的函数。
这就是我将把我的所有这些函数放的地方。欢迎您使用它们。
这些工具作为类上的静态方法实现。
截至目前,只有一个函数
ArrayUtils::val(array $array, $keys, $default = null)
从一个数组中挖掘出一个值,或者返回默认值。
use TimDev\ArrayUtils as A; $array = ['foo' => ['bar' => 'baz']]; // $baz == 'baz' $baz = A::val($array, ['foo', 'bar']); // $nope == null $nope = A::val($array, ['foo', 'bork']); // $nope == 'squee' $nope = A::val($array, ['i-do-not-exist'], 'squee'); // if you're just dereferencing by one level, you can pass int/string as second arg: // $foo == ['bar' => 'baz'] $foo = A::val($array, 'foo');