php - Sort Multi-dimensional Array by Size Value

Solution:
I suppose, you will process those files in a foreach loop.
How about the code below?
//get files in array
$files = $_FILES['formFieldName'];
$sizes = $files['size'];
arsort($sizes); //sort in descending order but will preserve the keys
foreach ($sizes as $key => $size) {
$fileName = $files['name'][$key];
$fileSize = $size;
$fileType = $files['type'][$key];
$fileTmpName = $files['tmp_name'][$key];
$fileError = $files['error'][$key];
}
Answer
Solution:
Based on Selim Mahmud's answer, I solved the solution:
$files = $_FILES['formFieldName'];
$sizes = $files['size'];
arsort($sizes); //sort in descending order but will preserve the keys
$files2 = array();
$i = 0;
foreach ($sizes as $key => $size) {
$files2['name'][$i] = $files['name'][$key];
$files2['type'][$i] = $files['type'][$key];
$files2['tmp_name'][$i] = $files['tmp_name'][$key];
$files2['error'][$i] = $files['error'][$key];
$files2['size'][$i] = $size;
$i++;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: uncaught mysqli_sql_exception
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.