-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

4
  • 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? Commented Apr 16, 2019 at 9:14
  • 2
    Possible duplicate of PHP Multiple File Array Commented Apr 16, 2019 at 9: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 Commented Apr 16, 2019 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... Commented Apr 16, 2019 at 13:29

1 Answer 1

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];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.