loganbest Posted October 19, 2010 Share Posted October 19, 2010 I have a bunch of PDF's, some of them having Uppercase first letters and some having lowercase first letters. Right now my code is alphabetizing all of the Uppercase first letters first then all of the lowercase. I want them to be mixed. $dir = "../../forms/pdf/"; foreach(glob($dir.'*.pdf') as $pdf){ $files[] = str_replace($dir, '', $pdf); } then: <select name="current_pdf" id="current_pdf"> <option value="">Please Select a PDF to replace</option> <?php foreach($files as $file) { echo "<option value=\"$file\">" . $file . "</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 http://us2.php.net/manual/en/function.natcasesort.php Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124037 Share on other sites More sharing options...
loganbest Posted October 19, 2010 Author Share Posted October 19, 2010 I've tried using that but I keep getting errors so I guess I'm putting it in the wrong place? Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124038 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2010 Share Posted October 19, 2010 Cannot help with errors without seeing the code that produces the error and the error. Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124041 Share on other sites More sharing options...
loganbest Posted October 19, 2010 Author Share Posted October 19, 2010 <?php $dir = "../../forms/pdf/"; foreach(glob($dir.'*.pdf') as $pdf){ $files[] = str_replace($dir, '', $pdf); } $files = natcasesort($files); ?> This does not populate the select box. <?php $dir = "../../forms/pdf/"; foreach(glob($dir.'*.pdf') as $pdf){ $files[] = str_replace($dir, '', $pdf); } $files[] = natcasesort($files[]); ?> This produces this error: Warning: natcasesort() [function.natcasesort]: The argument should be an array in /site_homes/www08/intra/pdf-upload/index2.php on line 6 Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124043 Share on other sites More sharing options...
AbraCadaver Posted October 19, 2010 Share Posted October 19, 2010 sorts don't return an array they modify the existing one. Here it is much shorter and probably faster: $files = array_map('basename', glob("../../forms/pdf/*.pdf")); natcasesort($files); Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124051 Share on other sites More sharing options...
AbraCadaver Posted October 19, 2010 Share Posted October 19, 2010 Also, I didn't even look at your error $files[] is only used to create the next item in the array, you refer to the array with just $files not $files[]. Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124056 Share on other sites More sharing options...
loganbest Posted October 19, 2010 Author Share Posted October 19, 2010 Hell it was faster. Thanks! Link to comment https://forums.phpfreaks.com/topic/216289-need-to-sort-a-literal-array/#findComment-1124077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.