Hướng dẫn php glob sort by filename - sắp xếp toàn cầu php theo tên tệp
Làm thế nào tôi có thể đảo ngược sắp xếp theo tên tệp? Hiện tại nó hiển thị tất cả các tệp văn bản theo thứ tự bảng chữ cái / số, nhưng tôi đang cố gắng hiển thị nó theo thứ tự giảm dần. Ngay bây giờ, tôi có ... Show
Tôi khá mới với PHP, nhưng tôi đã thử Usort với Array được thêm vào nhưng điều đó chỉ dẫn đến việc nó chỉ hiển thị 1 trong số các tệp văn bản, vì vậy hoặc không hoạt động hoặc tôi chỉ mã hóa nó sai.
Uwe keim 38.8K56 Huy hiệu vàng173 Huy hiệu bạc286 Huy hiệu Đồng56 gold badges173 silver badges286 bronze badges Hỏi ngày 10 tháng 10 năm 2011 lúc 3:55Oct 10, 2011 at 3:55
2 Bạn có thể sử dụng
Đã trả lời ngày 10 tháng 10 năm 2011 lúc 3:57Oct 10, 2011 at 3:57
Foo bahfoo bahFoo Bah 25.2K5 Huy hiệu vàng53 Huy hiệu bạc79 Huy hiệu đồng5 gold badges53 silver badges79 bronze badges Chỉ là một bổ sung cho câu trả lời của @foo Bah: Khi xử lý tên tệp trong thư mục, tôi thường thêm
Natsort là một thuật toán sắp xếp thân thiện với người dùng hơn sẽ bảo tồn đánh số tự nhiên:
Vì vậy, câu trả lời của Foobah trở thành:
Xin lưu ý rằng Đã trả lời ngày 5 tháng 5 năm 2019 lúc 13:03May 5, 2019 at 13:03
Gabriel Glenngabriel GlennGabriel Glenn 1.1341 Huy hiệu vàng12 Huy hiệu bạc28 Huy hiệu đồng1 gold badge12 silver badges28 bronze badges 0 Để có hiệu suất tối ưu, tôi sẽ đề nghị tránh xử lý mảng không cần thiết (nghĩa là sắp xếp hoặc đảo ngược) khi xử lý các mảng có khả năng lớn. Vì hàm glob () sắp xếp các tên tệp theo thứ tự tăng dần là hành vi mặc định, bạn chỉ cần lặp qua mảng kết quả theo thứ tự ngược lại và do đó tránh bất kỳ xử lý nào khác:
Đã trả lời ngày 19 tháng 3 năm 2018 lúc 8:58Mar 19, 2018 at 8:58
Cédric Françoyscédric FrançoysCédric Françoys 8221 Huy hiệu vàng10 Huy hiệu bạc22 Huy hiệu đồng1 gold badge10 silver badges22 bronze badges Cách để làm điều đó với
CodePad. Đã trả lời ngày 10 tháng 10 năm 2011 lúc 4:01Oct 10, 2011 at 4:01
Alexalexalex 469K197 Huy hiệu vàng868 Huy hiệu bạc977 Huy hiệu Đồng197 gold badges868 silver badges977 bronze badges 9 năm trước Parazuce [at] gmail [dot] com ¶ — Find pathnames matching a pattern 14 năm trướcnataxia tại gmail dot com(string
Gabriel S. Luraschi ¶Alan tại Synergymx Dot Com ¶AGD243 tại Gmail Dot Com ¶ Dman ¶
8 năm trước
$list = glob("*.jpg"); natsort($list); foreach(array_reverse($list) as $filename) { ... 27Bản phác thảo Nospam tại Infinite Dot Net Dot Au ¶
1 năm trướcDavewho tại Nexicom Dot Netglob() can replace opendir() and friends. 9Bitman tại Biitworks Dot de ¶ funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 137820
VinceWansink tại Outlook Dot Com ¶
Xem thêm
Crayonviolent tại phpfreaks dot com ¶ ¶ 13 năm trước
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378200 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378201 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378202 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378203 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378204 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378205 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378206 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Uramihsayibok, Gmail, com ¶ ¶ 13 năm trước funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378208 funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378209
array_reverse 1Uramihsayibok, Gmail, com ¶ ¶ redcube tại gmx dot de ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ Tối cao tại gmail dot com ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 11 năm trước ¶ ni dot pineau tại gmail dot com ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378209
natsort 110 năm trước ¶ ni dot pineau tại gmail dot com ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 10 năm trước ¶ Sam Bryan ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Ẩn danh ¶ ¶ Tối cao tại gmail dot com ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 11 năm trước ¶ 13 năm trước
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Uramihsayibok, Gmail, com ¶ ¶ redcube tại gmx dot de ¶
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ 13 năm trước
funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Uramihsayibok, Gmail, com ¶ ¶ redcube tại gmx dot de ¶ 00 01 02 03funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ Tối cao tại gmail dot com ¶ 05 06 07 0811 năm trước ¶ redcube tại gmx dot de ¶ 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ 13 năm trước 25 26 27 28Uramihsayibok, Gmail, com ¶ ¶ redcube tại gmx dot de ¶ 29 30 31 32 33 30 35 32funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ Tối cao tại gmail dot com ¶ 38 39 40 4111 năm trước ¶ ni dot pineau tại gmail dot com ¶ 42 43 4410 năm trước ¶ Sam Bryan ¶ 45Ẩn danh ¶ ¶ 1 năm trước 46 47funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 David Dot Schueler tại Tel-Billig Dot de ¶ ¶ redcube tại gmx dot de ¶ 49 50 51 5216 năm trước ¶ Sam Bryan ¶ 53 54 55 56 57funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Ẩn danh ¶ ¶ ni dot pineau tại gmail dot com ¶ 59 60funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 10 năm trước ¶ redcube tại gmx dot de ¶ 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ 1 năm trước
81David Dot Schueler tại Tel-Billig Dot de ¶ ¶ r dot hartung tại Roberthartung dot de ¶ 82 83funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Heavyraptor tại Gmail Dot Com ¶ ¶ 13 năm trước 85 86funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 10 năm trước ¶ r dot hartung tại Roberthartung dot de ¶ 88 89 90 91 92funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Heavyraptor tại Gmail Dot Com ¶ ¶ Sam Bryan ¶ 94 95 96 97funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Ẩn danh ¶ ¶ 1 năm trước 99 00funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 David Dot Schueler tại Tel-Billig Dot de ¶ ¶ 1 năm trước 02 03funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 David Dot Schueler tại Tel-Billig Dot de ¶ ¶ Tối cao tại gmail dot com ¶ 05 06 07 08funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 11 năm trước ¶ 13 năm trước 10 11 12 13funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Uramihsayibok, Gmail, com ¶ ¶ redcube tại gmx dot de ¶ 1516 năm trước ¶ Sam Bryan ¶ 16 17 18funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Ẩn danh ¶ ¶ Tối cao tại gmail dot com ¶ 20 21 22 2311 năm trước ¶ Tối cao tại gmail dot com ¶ 24 25 2611 năm trướcni dot pineau tại gmail dot com ¶ ¶ r dot hartung tại Roberthartung dot de ¶ 28 29 30 31funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Heavyraptor tại Gmail Dot Com ¶ ¶ redcube tại gmx dot de ¶ 33 34 35funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 16 năm trước ¶ Sam Bryan ¶ 37
Ẩn danh ¶ ¶ Sam Bryan ¶ 38Ẩn danh ¶ ¶ Sam Bryan ¶ 39 40 41 42 43funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Ẩn danh ¶ ¶ 1 năm trước 45 46 47 48 49funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 David Dot Schueler tại Tel-Billig Dot de ¶ ¶ Tối cao tại gmail dot com ¶ 51 52 53 5411 năm trước ¶ ni dot pineau tại gmail dot com ¶ 55 56 5710 năm trước ¶ ni dot pineau tại gmail dot com ¶ 58 59funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 10 năm trước ¶ Sam Bryan ¶ 61 62funclist.txt size 44686 funcsummary.txt size 267625 quickref.txt size 1378207 Joseph dot morphy tại gmail dot com ¶ ¶ 16 năm trước 64 65 66 |