# PHP sorting

**URL:** <https://forum.kirupa.com/t/php-sorting/215460>\
**Category:** programming\
**Created:** [February 7, 2007, 3:21pm UTC](https://forum.kirupa.com/t/php-sorting/215460 "2007-02-07T15:21:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imagined](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@imagined](https://forum.kirupa.com/u/imagined)\
**Post date:** [February 7, 2007, 3:21pm UTC](https://forum.kirupa.com/t/php-sorting/215460/1 "2007-02-07T15:21:14Z")

</div>

hello guys, long time i haven’t posted.

I create a while loop in which XML files are read from a folder. each XML file has information about a car, like Year, Model, Mileage, etc.

When they are displayed on the page (while loop), they are displayed from oldest to newest. Is there a way I can make them displayed from newest to oldest, sort by Price or sort by Year? I know there is the SORT function, but I read about it and it LOOKS like it only works with arrays.

```php

$handle = opendir($dirAutomobiles);
while(($file=readdir($handle)) !== FALSE) {
if(is_dir($dirAutomobiles . $file)) continue;
if(!eregi(".xml$", $file)) continue;

$automobileFile = simplexml_load_file($dirAutomobiles . $file);

echo $automobileFile->year;
echo $automobileFile->make;
echo $automobileFile->model;
echo $automobileFile->price;
}

```
