Skip to content

Instantly share code, notes, and snippets.

@mustafayusufozcan
Created May 23, 2021 21:12
Show Gist options
  • Select an option

  • Save mustafayusufozcan/ffae69bb9e3ea338aba49923db4daece to your computer and use it in GitHub Desktop.

Select an option

Save mustafayusufozcan/ffae69bb9e3ea338aba49923db4daece to your computer and use it in GitHub Desktop.
Reorders the array of multiple files sent
<?php
function multipleFiles($files_post) {
$files = [];
$keys = array_keys($files_post);
for($i = 0; $i < count($files_post["name"]); $i++) {
foreach($keys as $key) {
$files[$i][$key] = $files_post[$key][$i];
}
}
return $files;
}
/*
Input:
[
"name" => [
0 => "file1",
1 => "file2",
],
"type" => [
0 => "image/png",
1 => "image/gif"
]
];
Output:
[
0 => [
"name" => "file1",
"type" => "image/png"
],
1 => [
"name" => "file2",
"type" => "image/gif"
]
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment