Jump to content

Sort Array by Third Value - Date


TripleDES

Recommended Posts

Custom sort function and usort()

 

<?php

function mysort($a, $b)
{
    if ($a[2] == $b[2]) return 0;
    return ($a[2] < $b[2])  ?  -1 : 1;
}

$ar = array (
           array ('apple', 'orange', '2007-06-13'),
           array ('kiwi', 'pear', '2007-04-10'),
           array ('banana', 'nectarine', '2007-05-10')
        );

usort ($ar, 'mysort');

// check results

echo '<pre>', print_r($ar, true), '</pre>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.