這個小技巧你可能不知道。

yourself發表於2019-02-19
<?php

$data = [
    'testArray' => [
        'string1',
        'string2',
        [
            'string1',
            'string2',
        ],
    ],
    'teststring'
];
echo "<pre>";

print_r(iterator_to_array(
        new RecursiveIteratorIterator(
            new RecursiveArrayIterator($data)
        ),
        false  // use_keys:預設true
    )
);

/*Array
(
    [0] => string1
    [1] => string2
    [2] => string1
    [3] => string2
    [4] => teststring
)*/

相關文章