Skip to content

Instantly share code, notes, and snippets.

@widoz
Last active June 1, 2017 08:21
Show Gist options
  • Save widoz/24221a7e1fab73f79714c62b485110d9 to your computer and use it in GitHub Desktop.
Save widoz/24221a7e1fab73f79714c62b485110d9 to your computer and use it in GitHub Desktop.
Form Functions
<?php
/**
* Re Order Files
*
* @since ${SINCE}
* @access private
*
* @param array $list An array $_FILES like to re-order
*
* @return array The re-order array list
*/
private function reOrderFiles($list)
{
$newList = array();
/*
* If we are validating multiple files let's reorder them.
* By default the $_FILES structure is:
*
* [
* 'name' => [
* 0 => 'filename',
* 1 => 'filename',
* ],
* 'type' => [
* 0 => 'mimetype',
* 1 => 'mimetype',
* ]
* etc....
* ]
*
* We want to have the list ordered by index.
*/
foreach ($list as $name => $item) {
// Is multiple?
if (is_array($item['name'])) {
$numCicle = count($item['name']);
$keys = array_keys($list[$name]);
$internalCounter = count($keys);
for ($c = 0; $c < $numCicle; ++$c) {
for ($ic = 0; $ic < $internalCounter; ++$ic) {
$newList[$name][$c][$keys[$ic]] = $list[$name][$keys[$ic]][$c];
}
}
} else {
$newList[$name] = $item;
}
}
return $newList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment