You can use this snippet:
$max = null;
foreach ($arr as $worker) {
$max = $max === null ? $worker : ($worker->salary > $max->salary ? $worker : $max);
}
Or this, as more clarity:
$max = null;
foreach ($arr as $worker) {
if (!$max) {
$max = $worker;
} elseif ($worker->salary > $max->salary) {
$max = $worker;
}
}
$max now contains a worker with maximum salary.