数组操作类

获取值

/**
 * Gets a dot-notated key from an array, with a default value if it does
 * not exist.
 *
 * @param   array   $array    The search array
 * @param   mixed   $key      The dot-notated key or array of keys
 * @param   string  $default  The default value
 * @return  mixed
 */
public static function get($array, $key = null, $default = null, $filter_type = '', bool $throw_error = false)

有人戏称PHP为数组操作语言,懂array就懂PHP,但是PHP的数组操作实际上问题很多,比如:

$arr = [
    'name' => 'kaliphp'
];

echo $arr['country'];

在操作一个不存在的参数时,就会发送警告,我们不得不这样处理

echo $arr['country'] ?? 'HK';

有了数组操作类,我们便可以轻松化解这种尴尬😅

如果你觉得数组类只是为了解决参数不存在警告⚠️,那你就大错特错了,数据类可以让我们更加方便的获取多维数组的值,并且可以设置默认值。

通过表达式查询

简单用法

Last updated

Was this helpful?