force/arr

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

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

This package is not auto-updated.

Last update: 2024-09-12 06:22:21 UTC


README

Version License Total downloads Quality Score


安装

使用 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