Skip to content

数组工具 ArrUtility

App\Utilities\ArrUtility

获取指定数值

php
ArrUtility::get($array, $key, $values, $asArray);
参数名类型说明
arrayArray示例 [{"name":"language","canDelete":false},{"name":"errorUnknown","canDelete":false}]
keyString示例 name
valuesStringArray
asArrayBoolean结果仅剩一条时,是否保持为数组格式
  • 从数组中,获取指定键名为指定键值的数组。
  • 输出示例 {"name":"language","canDelete":false}

移除指定数值

php
ArrUtility::forget($array, $key, $values, $asArray);
参数名类型说明
arrayArray示例 [{"name":"language","canDelete":false},{"name":"errorUnknown","canDelete":false}]
keyString示例 name
valuesStringArray
asArrayBoolean结果仅剩一条时,是否保持为数组格式
  • 从数组中,移除指定键名为指定键值的数组。
  • 输出示例 [{"name":"errorUnknown","canDelete":false}]

返回并清理指定值

php
ArrUtility::pull($array, $key, $values, $asArray);
参数名类型说明
arrayArray示例 [{"name":"language","canDelete":false},{"name":"errorUnknown","canDelete":false}]
keyString示例 name
valuesStringArray
asArrayBoolean结果仅剩一条时,是否保持为数组格式
  • 从数组中返回指定键的值并删除此键值对。
  • 返回 {"name":"language","canDelete":false}
  • 传参的数组只剩下 [{"name":"errorUnknown","canDelete":false}]

编辑对象键名

php
ArrUtility::editKey($object, $key, $newKey);
参数名类型说明
objectObject示例 {"language":"Language","errorUnknown":"Unknown error"}
keyString示例 language
newKeyString示例 lang
  • 修改之后示例 {"lang":"Language","errorUnknown":"Unknown error"}

编辑数组值

php
ArrUtility::editValue($array, $key, $value, $newValue);
参数名类型说明
arrayArray示例 [{"name":"language","canDelete":false},{"name":"errorUnknown","canDelete":false}]
keyString示例 name
valueString示例 language
newValueString示例 lang
  • 修改之后示例 [{"name":"lang","canDelete":false},{"name":"errorUnknown","canDelete":false}]

Released under the Apache-2.0 License