I use below loop in form for saving data :
<form action="#" method="post" enctype="multipart/form-data">
<?php foreach ($sites as $site) { ?>
<div>
<div>
<input type="text" name="entry[<?= $site['id'] ?>][date]" id="repDate<?= $site['id'] ?>">
</div>
<div>
<input type="file" name="entry[<?= $site['id'] ?>][file]" id="repFile<?= $site['id'] ?>">
</div>
</div>
<?php } ?>
</form>
The output of the above code is as follows :
array(1) {
["entry"]=>
array(5) {
["name"]=>
array(2) {
[37]=>
array(1) {
["file"]=>
string(30) "my-file-test.docx"
}
[38]=>
array(1) {
["file"]=>
string(56) "resources_views.php"
}
}
["type"]=>
array(2) {
[37]=>
array(1) {
["file"]=>
string(71) "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
[38]=>
array(1) {
["file"]=>
string(17) "application/x-php"
}
}
["tmp_name"]=>
array(2) {
[37]=>
array(1) {
["file"]=>
string(14) "/tmp/phpahucFZ"
}
[38]=>
array(1) {
["file"]=>
string(14) "/tmp/phptnDGQR"
}
}
["error"]=>
array(2) {
[37]=>
array(1) {
["file"]=>
int(0)
}
[38]=>
array(1) {
["file"]=>
int(0)
}
}
["size"]=>
array(2) {
[37]=>
array(1) {
["file"]=>
int(12023)
}
[38]=>
array(1) {
["file"]=>
int(18174)
}
}
}
}
This array is the output of the above code.
Can somebody tell me how can I iterate this array in a sane way?
I want the same below output :
Array
(
[0] => Array
(
[name] => foo.txt
[type] => text/plain
[tmp_name] => /tmp/phpYzdqkD
[error] => 0
[size] => 123
)
[1] => Array
(
[name] => bar.txt
[type] => text/plain
[tmp_name] => /tmp/phpeEwEWG
[error] => 0
[size] => 456
)
)
I use below link but not work for me :
How can I iterate PHP $_FILES array?
Thanks for the help.