PHP tips : how to sort and reverse sort an array

Let’s say you had an array as following :

$time = array ("0600", "0000", "1200", "1800");

but you wanted it to be shown as

  1. 0000
  2. 0600
  3. 1200
  4. 1800

Use asort function..

asort ($time);

But you might also want to reverse order it.
Which is to show the latest possible date and time ..

arsort ($date_time_list);

Reference :
http://www.php.net/manual/en/function.asort.php
http://www.php.net/manual/en/function.arsort.php

Get Free Email Updates!

Signup now and receive an email once I publish new content.

I will never give away, trade or sell your email address. You can unsubscribe at any time.

Like

Related Post

2 Responses

  1. Patrick says:

    I was just curious as to what you use for your desktop OS? Is it primarily CentOS or Ubuntu? I’m considering CentOS but I haven’t seen many articles about really using it for a workstation.

    Reply
  2. owen says:

    Did you get further into GWT?

    Btw GWT is just javascript compiled via Java’s JRE, and the produced code is simply javascript. So if you want to code JS the most professional way – like IDE dev support, step debugging, and unit tests – use GWT.

    For me, I just love java. C# had a great future but Microsoft managed to screw it up somehow.

    Reply

Anything to add?

X