2010-03-06 96 views
0

我想將一個Zip歸檔文件組織成一個數組,以便我可以將某些文件提取到合適的位置。在一個數組中組織一個PHP Zip歸檔文件

Zip包含3個文件夾,並且在每個文件夾中包含可能根據其擴展名提取的文件。

郵編 - >文件夾1

-----文件1

-----文件2

-----文件3

- >文件夾2

-----文件1

-----文件2

- >文件夾3

-----文件1

-----文件2

在時刻,文件夾進行數值命名。

文件夾1

文件夾1.1

文件夾2

然而,當我把它們在一個循環來描述statIndex到一個數組,該文件夾被重新排列爲跟隨在陣列中:

陣列[0] =文件夾1

陣列[1] = 2夾

array [2] =文件夾1.1

我想對statIndex進行排序,以便文件夾1會出現在文件夾1之後,然後出現文件夾1.1,文件夾2之後。

數組的鍵對於組織數據很重要,因此我需要幫助排序statIndex。因此:

陣列[0] =文件夾1

陣列[1] = 1.1的文件夾

陣列[2] = 2夾

幫助十分讚賞。

我的代碼:http://pastebin.com/6VRvWPqr

回答

1

您可以使用natsort到你想要的數組排序。

<?php 

$values = array('Folder 1', 'Folder 2', 'Folder 1.1'); 

// Unordered. 
print_r($values); 

// Sort the values. 
natsort($values); 

// Ordered 
print_r($values); 

輸出

Array 
(
    [0] => Folder 1 
    [1] => Folder 2 
    [2] => Folder 1.1 
) 
Array 
(
    [0] => Folder 1 
    [2] => Folder 1.1 
    [1] => Folder 2 
)