0

我是 php 的初学者,我有一个变量,关于上传图像的信息

我得到一个多维数组

Array
(
    [0] => Array
        (
            [errors] => Array
                (
                )

            [path] => addons/uploads/albums/1/1/rDtKgyVAvTjSkLA.jpg
            [filename] => rDtKgyVAvTjSkLA.jpg
            [original_name] => rachaelCache_5750270_thm.jpg
            [resizes] => Array
                (
                    [0] => 1
                    [1] => 1
                )

        )

    [1] => Array
        (
            [errors] => Array
                (
                )

            [path] => addons/uploads/albums/1/1/qTLglBgAPxvDFtr.png
            [filename] => qTLglBgAPxvDFtr.png
            [original_name] => Screen Shot 2013-03-02 at 11.28.48 AM.png
            [resizes] => Array
                (
                    [0] => 1
                    [1] => 1
                )

        )

)

但是当我 foreach 它时,我只能得到一个结果

foreach ($upload as $row) {
   echo $row['filename'];
}

请有人告诉我为什么会这样?

4

1 回答 1

0

将您的代码重新创建为实时演示,效果很好:---> http://3v4l.org/986e7

$upload = array(array(
        'errors' => array(), 
        'filename' => '/some/path/to/a/file.jpg'), 
    array(
        'errors' => array(), 
        'filename' => '/yet/another/path.jpg'));

var_dump($upload);

foreach ($upload as $x) 
    echo $x['filename'],"<br>";

echo $upload[0]['filename'];

为了找出问题所在,我会var_dump($upload);在您的 -loop 之前放置一个权利,foreach以查看 $upload 是否包含您认为的内容。

于 2013-03-22T15:36:02.493 回答