Let's say I have an object called ACCOUNT like:
class ACCOUNT
{
private $contact;
public function getContact();
}
and another object CONTACT:
class CONTACT
{
private $lastName;
public function getLastName()
{
return $this->lastName;
}
}
Then I create an array of these objects $accountArray = ACCOUNT::get();
How can I sort this array alphabetically by something like $account->getContact()->getLastName();?
What I've tried:
class Account
{
private $contact;
public function getContact();
public static function cmp($a,$b)
{
$al = strtolower($a->getContact()->getLastName());
$bl = strtolower($b->getContact()->getLastName());
if ($al == $bl) {
return 0;
}
return ($al > $bl) ? +1 : -1;
}
public static function sortByLastName($accountArray)
{
usort($moACOUNTArray, array('ACCOUNT', 'cmp'));
}
}
But I get this error:
Call to undefined method ACCOUNT::getContact()
staticif it's intended to be called using the class-name alone. Or else an object will have to be created using which it could be invoked. Reference manual