Created
May 23, 2021 21:12
-
-
Save mustafayusufozcan/ffae69bb9e3ea338aba49923db4daece to your computer and use it in GitHub Desktop.
Reorders the array of multiple files sent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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