-1

I have an array like the first picture below. Is it possible to re-arrange the array position like the second picture below? So that it can arranged file0, file1, file2 and so on.

Multiple Array

enter image description here

Single Array

enter image description here

Sebastian Kaczmarek
  • 8,120
  • 4
  • 20
  • 38
LearnProgramming
  • 814
  • 1
  • 12
  • 37
  • Do the same indexes correspond to the same file? For example `name[0], error[0], size[0]` is one file and `name[1], error[1], size[1]` is another file? `name`, `error` etc arrays have the same size? – Sebastian Kaczmarek Apr 16 '19 at 09:14
  • 2
    Possible duplicate of [PHP Multiple File Array](https://stackoverflow.com/questions/15941592/php-multiple-file-array) – Scoots Apr 16 '19 at 09:42
  • @SebastianKaczmarek yes, `name[0], error[0], size[0] is one file and name[1], error[1], size[1] is another file and so on` but the value of each indexes are different – LearnProgramming Apr 16 '19 at 13:28
  • @Scoots I dont think the link is going to help me because it does not sort any arrays...it is telling how to upload multiple files... – LearnProgramming Apr 16 '19 at 13:29

1 Answers1

1

Never mind, I solved my own answer by sorting like this

$count = count($_FILES['file']['name']);
$sort_arr = [];
for ($i=0; $i < $count; $i++) { 
    $sort_arr['file'.$i]['name'] = $_FILES['file']['name'][$i];
    $sort_arr['file'.$i]['type'] = $_FILES['file']['type'][$i];
    $sort_arr['file'.$i]['tmp_name'] = $_FILES['file']['tmp_name'][$i];
    $sort_arr['file'.$i]['error'] = $_FILES['file']['error'][$i];
    $sort_arr['file'.$i]['size'] = $_FILES['file']['size'][$i];
}
LearnProgramming
  • 814
  • 1
  • 12
  • 37