该软件包已被废弃且不再维护。作者建议使用 flextype-components/arrays 软件包。

数组组件包含在处理数组时可能有用的方法。

v3.0.1 2020-07-24 14:54 UTC

This package is auto-updated.

Last update: 2020-08-19 12:35:02 UTC


README

Version License Total downloads Quality Score


安装

使用 Composer

composer require flextype-components/arrays

用法

use Flextype\Component\Arrays;

方法

方法 描述
Arrays::set() 使用“点”表示法将数组项设置为给定值。如果没有为方法提供键,则整个数组将被替换。
Arrays::get() 使用“点”表示法从数组返回值。如果键在数组中不存在,则返回默认值。
Arrays::delete() 使用“点”表示法删除数组值。
Arrays::has() 检查给定的点表示法键是否存在于数组中。
Arrays::dot() 使用点将多维关联数组展平。
Arrays::undot() 将点表示法数组展开为完整的多维数组。

方法: 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