[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Sorting an array

Posted on 2004-08-30
1
Medium Priority
?
292 Views
Last Modified: 2006-11-17
Hello.

I to create an array, I place this line in three different mySQL table queries:

------------------------------------------------------
$list[] = array("tstamp" => $row[TSTAMP], "title" => $row[TITLE], "notes" => $row[notes]);
------------------------------------------------------

Now I have an array with 40 items, and I want to sort them in ascending order by tstamp (an integer).

I looked at the PHP manual pages, but got confused by the many sorting functions:
arsort(), asort(), ksort(), natsort(), natcasesort(), rsort(), usort(), array_multisort(), and uksort().

What is the easiest way to sort this array by tstamp?
0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 11935769
The following code should do what you want

// define you sorting function
function mycmp($a,$b) {
    if ($a['tstamp'] == $b['tstamp']) {
        return 0;
    }
    return $a['tstamp'] > $b['tstamp'] ? 1 : -1;
}

usort($list, 'mycmp');
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question