多个阵列成单个阵列

时间:2014-09-07 13:19:35

标签: php arrays

是否有解决方案将此阵列拆分为单个阵列?

像:
['userfile1'] = array(name => everybodytalkings.jpg)等 ['userfile2'] = array(name => glove.png)等。

试图解决一个问题,已经持续了3个小时,而且还有这个问题。 真的希望有人可以帮助我

[userfile] => Array
    (
        [name] => Array
            (
                [0] => everybodytalkings.jpg
                [1] => glove.png
            )

        [type] => Array
            (
                [0] => image/jpeg
                [1] => image/png
            )

        [tmp_name] => Array
            (
                [0] => /home/christiant.wi8/tmp/phpNmvGeZ
                [1] => /home/christiant.wi8/tmp/phpGjsRrl
            )

        [error] => Array
            (
                [0] => 0
                [1] => 0
            )

        [size] => Array
            (
                [0] => 65188
                [1] => 75182
            )

    )

1 个答案:

答案 0 :(得分:0)

不确定,如果这是您正在寻找的(您的“等。”不是很精确)。但是试试

$new = array();

foreach($userfile as $key => $item) {
    $new['userfile1'][$key] = $item[0];
    $new['userfile2'][$key] = $item[1];
}

会给你

Array
(
    [userfile1] => Array
        (
            [name] => everybodytalkings.jpg
            [type] => image/jpeg
            [tmp_name] => /home/christiant.wi8/tmp/phpNmvGeZ
            [error] => 0
            [size] => 65188
        )

    [userfile2] => Array
        (
            [name] => glove.png
            [type] => image/png
            [tmp_name] => /home/christiant.wi8/tmp/phpGjsRrl
            [error] => 0
            [size] => 75182
        )

)

请参阅example