PHP sorting an array by mysql date.

Posted by daviemanchester on Stack Overflow See other posts from Stack Overflow or by daviemanchester
Published on 2010-04-20T17:32:35Z Indexed on 2010/04/20 17:33 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

Hi

I have an array that I would like to sort using a date field from a mysql database.

Here is a sample of the array which is named 'news' in my class:

[48] => Array
    (
        [id] => 14
        [type] => 3
        [updated] => 2010-04-17 13:54:42
    )

[49] => Array
    (
        [id] => 15
        [type] => 3
        [updated] => 2010-04-17 13:57:21
    )

I want to sort de by the 'updated' field.

I have some code I have started but am unsure how to complete it and get it working.

    function sortNews($x)
 {
     usort($this->news, array("ProcessClass", "cmp")); //correct sort type?
       }

   function cmp($a, $b)
 {

...................................... missing code }

Can anyone help??

© Stack Overflow or respective owner

Related posts about php

Related posts about array