-4

How to loop in array of arrays. I want to access the [name] but I don't know how to start. Please help. I'm using zend framework

(
[formdata] => {"profilename":"test"}
[fileUpload] => Array
    (
        [file] => Array
            (
                [name] => 108-thumb_709.jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpg1PQRN
                [error] => 0
                [size] => 62869
            )

    )
 )
Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54
qazzu
  • 361
  • 3
  • 5
  • 16

1 Answers1

0

This is not relative to zend framework, it's relative to PHP basics.

For loop into a multiple array you can do this :

<?php

foreach ($myArray['fileUpload'] as $file) {
    var_dump($file['name']),
}

You can take a look to this question And this PHP manual for foreach

If you have a structure like this :

array(
    1 => array(
        'formdata' => {"profilename":"test"}
        'fileUpload' => array(
            'file' => array(
                'name' => '108-thumb_709.jpg',
                'type' => 'image/jpeg',
                'tmp_name' => '/tmp/phpg1PQRN',
                'error' => '0',
                'size' => '62869',
            )
        )
    ),
    2 => array(
        'formdata' => {"profilename":"test"}
        'fileUpload' => array(
            'file' => array(
                'name' => '108-thumb_709.jpg',
                'type' => 'image/jpeg',
                'tmp_name' => '/tmp/phpg1PQRN',
                'error' => '0',
                'size' => '62869',
            )
        )
    ),
);

You have to do like this :

foreach ($myArray as $key => $value) {
    foreach ($value['fileUpload'] as $file) {
        var_dump($file['name']),
    }
}
Community
  • 1
  • 1
Greco Jonathan
  • 2,517
  • 2
  • 29
  • 54