Tuesday, March 03, 2009

sorting dengan usort di php

function cmp($a, $b)
{
if ($a->a == $b->a) {
return 0;
}
return ($a->a < $b->a) ? -1 : 1;
}

$ob1->a = 10;
$ob2->a = 2;

$ar = array($ob1, $ob2);

usort($ar, "cmp");

var_dump($ar);


//-- end of php code

No comments:

Post a Comment