# Howto: sort a csv file in numeric order

**URL:** <https://forum.kirupa.com/t/howto-sort-a-csv-file-in-numeric-order/255112>\
**Category:** Uncategorized\
**Created:** [March 19, 2008, 6:02am UTC](https://forum.kirupa.com/t/howto-sort-a-csv-file-in-numeric-order/255112 "2008-03-19T06:02:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Utech22](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@Utech22](https://forum.kirupa.com/u/Utech22)\
**Post date:** [March 19, 2008, 6:02am UTC](https://forum.kirupa.com/t/howto-sort-a-csv-file-in-numeric-order/255112/1 "2008-03-19T06:02:50Z")

</div>

I want to sort the csv file in numeric order using the coloum id  
I tried sort\_numeric and it would not work maybe I was not using it correctly.  
I want to sort this dropdown list, numerically by it value.

```php
 
<option value="0"> Select your State </option>
<?PHP
//open csv file then display the result in the dropdown list
$file_handle = fopen("file1.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
//define coloum needed to be displayed from the csv file.
$index = $line_of_text[0];
$value = $line_of_text[1];
?>
<option value="<?php print $index; ?>"> <?php print $value; ?> </option>
<?php
}
?></select><?php
fclose($file_handle);
?>

```
