/** * Get sorted result iterator for the records on the current page * * Note: this method will not query Salesforce for records outside the * current page. If you wish to sort larger sets of Salesforce records, do * so in the select query you issue to the Salesforce API. * * @param string $by * * @return \ArrayIterator */ public function sort($by) { $by = ucfirst($by); $array = $this->queryResult->getRecords(); usort($array, function ($a, $b) use($by) { // These two ifs take care of moving empty values to the end of the // array instead of the beginning if (!isset($a->{$by}) || !$a->{$by}) { return 1; } if (!isset($b->{$by}) || !$b->{$by}) { return -1; } return strcmp($a->{$by}, $b->{$by}); }); return new \ArrayIterator($array); }