Reputation: 796
I am trying to organize a Zip Archive into an array so that I may extract certain files into their rightful place.
The Zip contains 3 folder, and in each folder holds files that may be extracted depending on their extension.
Zip -> Folder 1
-----File 1
-----File 2
-----File 3
-> Folder 2
-----File 1
-----File 2
-> Folder 3
-----File 1
-----File 2
At the moments, the folder are named numerically.
Folder 1
Folder 1.1
Folder 2
However, when I put them in a loop to describe the statIndex to an array, the folder are rearrange as follow in the array:
array[0] = Folder 1
array[1] = Folder 2
array[2] = Folder 1.1
I am trying to sort the statIndex so that Folder 1.1 would come after Folder 1, then after Folder 1.1, Folder 2 would come.
The Key of the array are important for organizing the data, and thus why I need help sorting statIndex. Thus:
array[0] = Folder 1
array[1] = Folder 1.1
array[2] = Folder 2
Help is very appreciated.
My Code: http://pastebin.com/6VRvWPqr
Upvotes: 0
Views: 547
Reputation: 13430
You can use natsort to sort the array how you want it.
<?php
$values = array('Folder 1', 'Folder 2', 'Folder 1.1');
// Unordered.
print_r($values);
// Sort the values.
natsort($values);
// Ordered
print_r($values);
Output
Array
(
[0] => Folder 1
[1] => Folder 2
[2] => Folder 1.1
)
Array
(
[0] => Folder 1
[2] => Folder 1.1
[1] => Folder 2
)
Upvotes: 1