Skip to content

Instantly share code, notes, and snippets.

@guilherme
Created July 12, 2011 21:55
Show Gist options
  • Save guilherme/1079074 to your computer and use it in GitHub Desktop.
Save guilherme/1079074 to your computer and use it in GitHub Desktop.
<?php
// This function extract the rows of arrays like $_FILE when using the option 'multiple'
// For ex.
// Array
// (
// [name] => Array
// (
// [0] => uploaded_file1
// [1] => uploaded_file2
// [2] => uploaded_file3
// [3] => uploaded_file4
// )
//
// [type] => Array
// (
// [0] => application/octet-stream
// [1] => application/octet-stream
// [2] => application/octet-stream
// [3] => application/octet-stream
// )
//
// [tmp_name] => Array
// (
// [0] => /private/var/tmp/phpb4cVKW
// [1] => /private/var/tmp/phpmVaXZV
// [2] => /private/var/tmp/phpYnUhEu
// [3] => /private/var/tmp/phpoTmONA
// )
//
// [error] => Array
// (
// [0] => 0
// [1] => 0
// [2] => 0
// [3] => 0
// )
//
// [size] => Array
// (
// [0] => 339
// [1] => 1281
// [2] => 909
// [3] => 979
// )
//
// )
//
// INTO A MORE FRIENDLY FORMAT LIKE:
//
// Array
// (
// [0] => Array
// (
// [name] => uploaded_file1
// [type] => application/octet-stream
// [tmp_name] => /private/var/tmp/phpb4cVKW
// [error] => 0
// [size] => 339
// )
//
// [1] => Array
// (
// [name] => uploaded_file2
// [type] => application/octet-stream
// [tmp_name] => /private/var/tmp/phpmVaXZV
// [error] => 0
// [size] => 1281
// )
//
// [2] => Array
// (
// [name] => uploaded_file3
// [type] => application/octet-stream
// [tmp_name] => /private/var/tmp/phpYnUhEu
// [error] => 0
// [size] => 909
// )
//
// [3] => Array
// (
// [name] => uploaded_file4
// [type] => application/octet-stream
// [tmp_name] => /private/var/tmp/phpoTmONA
// [error] => 0
// [size] => 979
// )
//
// )
function extract_rows($table) {
$keys = array_keys($table);
$rows = array();
for($i = 0; $i < sizeof($table[$keys[0]]);$i++) {
$row = array();
for($j = 0; $j < sizeof($keys); $j++) {
$row[$keys[$j]] = $table[$keys[$j]][$i];
}
array_push($rows,$row);
}
return $rows;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment