lucasantarella/array_keys_recursive

用于获取多维数组键值的库,同时保留原始数组结构。

1.0.0 2017-11-22 19:11 UTC

This package is auto-updated.

Last update: 2024-09-05 11:59:29 UTC


README

Build Status License Issues

描述

一个用于获取多维数组 array_keys() 的简单库。

安装

Composer

$ composer require lucasantarella/php-array-keys-recursive

用法

<?php

require_once __DIR__ . '/vendor/autoload.php';

$input = [
    'person' => [
        'name' => [
            'first' => 'Luca',
            'middle' => 'Michele',
            'last' => 'Santarella'
        ],
        'dob' => '11/11/1999',
        'knowledge' => [
            'programming' => [
                'languages' => [
                    'PHP',
                    'JS',
                    'HTML',
                    'SQL',
                    'JAVA'
                ]
            ]
        ]
    ]
];

$output = \LucaSantarella\ArrayKeysRecursive::getKeys($input);

结果

array (
  'person' => 
  array (
    'name' => 
    array (
      0 => 'first',
      1 => 'middle',
      2 => 'last',
    ),
    0 => 'dob',
    'knowledge' => 
    array (
      'programming' => 
      array (
        'languages' => 
        array (
          0 => 0,
          1 => 1,
          2 => 2,
          3 => 3,
          4 => 4,
        ),
      ),
    ),
  ),
)