希望有人能指出我在這裏向正確的方向...創建從平面陣列新的多維數組 - 目錄路徑 - PHP
我有目錄路徑和部分文件輸出形成UNIX的grep。我從這些輸出有一個平面陣列。現在我想做一點PHP魔術,將這個平面陣列變成更分層的多維數組,以便更精細的用戶輸出
當前數組;
array(7) {
[0]=>
string(160) "/home/user/data/section1/dir1/20120107/filename.txt:random text after the colon"
[1]=>
string(160) "/home/user/data/section1/dir1/20120108/filename.txt: More random text after the colon"
[2]=>
string(160) "/home/user/data/section1/dir2/20120107/filename.txt: More random text after the colon"
[3]=>
string(160) "/home/user/data/section1/dir2/20120108/filename.txt: More random text after the colon"
[4]=>
string(160) "/home/user/data/section1/dir3/20120107/filename.txt: More random text after the colon"
[5]=>
string(160) "/home/user/data/section1/dir3/20120106/filename.txt: More random text after the colon"
[6]=>
string(160) "/home/user/data/section1/dir3/20120108/filename.txt: More random text after the colon"
}
什麼我真的想
array(1) {
array(3) {
["dir"]=>
string(4) "dir1"
["date"]=>
string(8) "20120107"
["text"]=>
array (2) {
[0]=>
string(160) "random text after the colon"
[1]=>
string(160) "More random text after the colon"
}
}
array(3) {
["dir"]=>
string(4) "dir1"
["date"]=>
string(8) "20120108"
["text"]=>
array (2) {
[0]=>
string(160) "More random text after the colon"
[1]=>
string(160) "More random text after the colon"
}
}
array(3) {
["dir"]=>
string(4) "dir2"
["date"]=>
string(8) "20120107"
["text"]=>
array (2) {
[0]=>
string(160) "More random text after the colon"
[1]=>
string(160) "More random text after the colon"
}
}
}
我已經嘗試了很多的foreach的,SPL迭代方法,但我只是不出來王牌。尋找任何指導。
感謝所有
你可以發佈你已經嘗試過嗎? –
目前還不清楚爲什麼每個條目有兩個「隨機」字符串... – Amarnasan