mitsuru793/array-helper-function
Composer 安装命令:
composer require mitsuru793/array-helper-function
包简介
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
README 文档
README
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
Installation
if you're using Composer to manage dependencies, you can include the following in your composer.json file:
"require": { "mitsuru793/array-helper-function }
Then, after running composer update or php composer.phar update, you can load the class using Composer's autoloading:
require 'vendor/autoload.php';
Functions
condtion
each
access
Function detail
is_empty_array($value): bool
Finds whether a variable is a empty array.
return true when value is
[]
returns false when value is
- not array(ex:
0,1,true,null...) [1, 2][null][[], []]
is_empty_array([]) // true
is_full_array($value): bool
Finds whether a variable is a full array, so it's not empty array.
return true when value is
[1, 2][null][[], []]
returns false when value is
[]- not array(ex:
0,1,true,null...)
is_full_array([1]) // true
is_numeric_array($value): bool
Finds whether all keys of variable are integer. This does not find deeply if element of $value is array.
return true when value is
[][null][['k1' => 'v1'], 'v2]
returns false when value is
- not array(ex:
0,1,true,null...) ['k1' => 'v1', 'v2]
is_numeric_array([1]) // true
is_numeric_array_recursive($array): bool
Finds whether all keys of variable are integer deeply. This is like is_numeric_array
return true when value is
[][null]
returns false when value is
- not array(ex:
0,1,true,null...) ['k1' => 'v1', 'v2][['k1' => 'v1'], 'v2]
is_numeric_array_recursive([1]) // true
array_every(array $array, callable $test = null): bool
Verify that all elements of a $array pass a given truth $test.
array_every([1, 2, 3], function ($value, $key) { retrun $value > 2; }); // false
If the $array is empty, every will return true.
array_every([]) // true
If the $test is null, verify all them are truly.
array_every([1, 2, 3]); // true
array_any(array $array, callable $test = null): bool
Verify that a element of a $array pass a given truth $test.
array_every([1, 2, 3], function ($value, $key) { retrun $value > 2; }); // true
If the $array is empty, every will return false.
array_every([]) // false
If the $test is null, verify one is truly.
array_every([1, 2, 3]); // true
array_keys_recursive(array $array): array
This is like array_keys, but recursively. Return combinations of all keys.
$array = [ 'Japan' => [ 'Tokyo' => [ 'user1' => 'Mike', 'user2' => 'Jane', 'Hiro', 'Hanako', ], 'Kyoto' => [], ], 'Take', ]; array_keys_recursive($array); // [ // ['Japan', 'Tokyo', 'user1'], // ['Japan', 'Tokyo', 'user2'], // ['Japan', 'Tokyo', 0], // ['Japan', 'Tokyo', 1], // ['Japan', 'Kyoto'], // 0, // ]
array_diff_key_recursive(array $main, array $other): array
This is like array_diff_key, but recursively.
$main = [
'user' => [
'name' => 'Mike',
'age' => 20,
],
];
$other = [
'id' => 2,
'user' => [
'name' => 'Jane',
'from' => 'America',
'sex' => 'woman',
],
];
array_diff_key_recursive($main, $other));
// [
// 'user' => [
// 'age' => 20
// ]
// ]
array_diff_key_recursive($other, $main));
// [
// 'id' => 2,
// 'user' => [
// 'from' => 'America',
// 'sex' => 'woman',
// ],
// ]
array_filter_recursive($array, callable $test = null): array
This is like array_filter, but recursively. The closure $test is passed $key by default.
$array = [ 'Japan' => [ 'Hiroki-Man', 'Kaede-Woman', 'Tokyo' => [ 'Taro-Man', 'Hanako-Woman', ], ], 'America' => [ 'Jane-Woman', 'Mike-Man', ], ]; array_filter_recursive($array, function ($v, $k) { if (!is_string($v)) { return true; } return preg_match('/Man/', $v); }); // [ // 'Japan' => [ // 'Hiroki-Man', // 'Tokyo' => [ // 'Taro-Man', // ], // ], // 'America' => [ // 1 => 'Mike-Man', // ], // ]
array_get(array $array, $path, string $separator = '.')
Retrieves a value from a nested array. Notation of $path is dot or array. If $path is string, you can modify its separator from dot as 3rd argument.
$array = [ 'user' => [ 'name' => 'mike', ], ]; array_get($array, ['user', 'name']); array_get($array, 'user.name'); array_get($array, 'user_name', '_'); // mike array_get($array, 'invalid'); // null
array_set(array &$array, $path, $value, string $separator = '.'): void
Set a $value within a nested array. Notation of $path is dot or array. If $path is string, you can modify its separator from dot as 3rd argument.
$array = []; array_set($array, ['user', 'name'], 'Mike'); array_set($array, 'user.name', 'Mike'); array_set($array, 'user_name', 'Mike', '_'); $array; // [ // 'user' => [ // 'name' => 'Mike' // ] // ]
array_unset(array &$array, $path, string $separator = '.'): void
Set a $value within a nested array. Notation of $path is dot or array. If $path is string, you can modify its separator from dot as 3rd argument.
$array = [ 'user' => [ 'name' => 'Mike', ], ]; array_unset($array, ['user', 'name']); array_unset($array, 'user.name'); array_unset($array, 'user_name', '_'); $array; // [ // 'user' => [] // ]
array_pick(array &$array, array $values): array
Find whether $values match elements of $array strictly, and takes matched values from $array. Has side effect and modify $array.
$array = ['a', null, true, 'b'];
$picked;
// [0 => 'a', 2 => true]
$array;
// [1 => null, 3 => 'b']
mitsuru793/array-helper-function 适用场景与选型建议
mitsuru793/array-helper-function 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.57k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「util」 「array」 「function」 「helper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mitsuru793/array-helper-function 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mitsuru793/array-helper-function 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mitsuru793/array-helper-function 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Camilo3rd's PHP Utils Library
Collection of exception class and utilities
PHP-ClamAV library - to scan the file for viruses
PHPUnit extension to Mock PHP internal functions using Runkit.
Collection of methods that I or you usually use.
统计信息
- 总下载量: 3.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-10