Created
July 28, 2021 21:36
-
-
Save Dennis14e/fc0cdbb37375cdb5be8d1c11a1823a0b to your computer and use it in GitHub Desktop.
PHP: Rearrange $_FILES array
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 rearrangeFiles($files) | |
| { | |
| $ret = []; | |
| foreach ($files as $name => $keys) { | |
| if (!is_array($keys['name'])) { | |
| $ret[$name] = [ $keys ]; | |
| continue; | |
| } | |
| foreach (array_keys($keys['name']) as $key) { | |
| $ret[$name][$key] = [ | |
| 'name' => $keys['name'][$key], | |
| 'type' => $keys['type'][$key], | |
| 'tmp_name' => $keys['tmp_name'][$key], | |
| 'error' => $keys['error'][$key], | |
| 'size' => $keys['size'][$key], | |
| ]; | |
| } | |
| } | |
| return $ret; | |
| } | |
| $_FILES = rearrangeFiles($_FILES); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment