Jump to content

Need to sort a literal array


loganbest

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.