php - Why isn't natsort (or natcasesort) working here? -
Maybe I'm doing wrong with some embarrassment, but why is this array not being solved?
$ narray = array (); $ Dir_handle = @opendir ($ path. $ Projectfolder) or die ("Unable to open $ $ path project folder"); $ I = =; While ($ file = readdir ($ dir_handle)) {$ filenameSplit = explode ('.', $ File); If ($ file! = "." & Amp; $ file! = ".." & amp; $ filenameSplit [0]! = "Logo" & amp; amp; $ filenameSplit [1]! = "ZIP" & amp ;; & Amp; $ filenameSplit [1]! = "Pdf" & amp; amp; $ filenameSplit [1]! = "Doctor" & amp; amp; $ filenameSplit [1]! = "Psd" & amp; amp; $ FilenameSplit [1]! = "") {$ Narray [$ i] = $ file; $ I ++; }} Natcasesort ($ narray);
I think that when I do not try to sort the array at all, I'm getting the same result. sort ()
works but nothing seems to be.
Thanks for any help!
Update:
Here are the sample results:
No Sort :
< code> 03_piper_file-manager_02.jpg 05_piper_login-page_02.jpg 02_piper_file-manager_no-slides_01.jpg 04_piper_file -manager_02.jpg 01_piper_file-manager_no-slides_01.jpg
the Sort ( )
:
01_piper_file-manager_no-slides_01 JPG 02_piper_file-manager_no-slides_01.jpg 03_piper_file-manager_02.jpg 04_piper_file-manager_02.jpg 05_piper_login-page_02.jpg
the natsort ()
or natcasesort ()
:
03_piper_file-manager_02.jpg 05_piper_login-page_02.jpg 02_piper_file -manager_no-slides_01.jpg 04_piper_file-manager_02.jpg 01_piper_file-manager_no-slides_01.jpg
I look like the type Area is much less than expected to result natsort.
Try after code natcasesort The key / value belongs, so if you have an index If you are repetitive on the array, you will see this behavior.
. You can iterate the array using foreach. print_r ($ narray)
> natcasesort
foreach ($ narray as $ $) work on $ {/ * $ = *}