flextype-components / arrays
数组组件包含在处理数组时可能有用的方法。
v3.0.1
2020-07-24 14:54 UTC
Requires
- php: >=7.2.0
Requires (Dev)
- doctrine/coding-standard: 7.0.2
README
安装
使用 Composer
composer require flextype-components/arrays
用法
use Flextype\Component\Arrays;
方法
方法: Arrays::set()
使用“点”表示法设置数组项为给定值。如果没有提供键给方法,则整个数组将被替换。
Arrays::set($array, 'movies.the-thin-red-line.title', 'The Thin Red Line');
方法: Arrays::get()
使用“点”表示法从数组返回值。如果键在数组中不存在,则返回默认值。
Arrays::get($array, 'movies.the-thin-red-line.title')
方法: Arrays::delete()
使用“点”表示法删除数组值。
Arrays::delete($array, 'movies.the-thin-red-line');
方法: Arrays::has()
检查给定的点表示法键是否存在于数组中。
if (Arrays::has($array, 'movies.the-thin-red-line')) { // Do something... }
方法: Arrays::dot()
使用点将多维关联数组展平。
$array = [ 'movies' => [ 'the_thin_red_line' => [ 'title' => 'The Thin Red Line', 'directed_by' => 'Terrence Malick', 'produced_by' => 'Robert Michael, Geisler Grant Hill, John Roberdeau', 'decription' => 'Adaptation of James Jones autobiographical 1962 novel, focusing on the conflict at Guadalcanal during the second World War.', ], ], ]; $newArray = Arrays::dot($array);
方法: Arrays::undot()
将点表示法数组展开为完整的多维数组。
$array = [ 'movies.the_thin_red_line.title' => 'The Thin Red Line', 'movies.the_thin_red_line.directed_by' => 'Terrence Malick', 'movies.the_thin_red_line.produced_by' => 'Robert Michael, Geisler Grant Hill, John Roberdeau', 'movies.the_thin_red_line.decription' => 'Adaptation of James Jones autobiographical 1962 novel, focusing on the conflict at Guadalcanal during the second World War.', ]; $newArray = Arrays::undot($array);
许可协议
MIT 许可协议 (MIT) 版权所有 (c) 2020 Sergey Romanenko