Created
March 23, 2012 18:08
-
-
Save makepanic/2173332 to your computer and use it in GitHub Desktop.
a PHP natcasesort function that returns a sorted array with modified indexes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function natcasesortWrite($arr){ | |
natcasesort($arr); | |
return array_values($arr); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function natcasesortWrite($arr){ | |
//Use natcasesort and save to new array (for php < 5.4) | |
if(is_array($arr)){ | |
$tmpArray=array(); | |
natcasesort($arr); | |
for($i=count($arr);$i>0;$i--){ | |
$tmpArray[$i-1]=array_pop($arr); | |
} | |
return $tmpArray; | |
}else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment