When using Model::getList() method, you may want to retrieve the records in specific order. Use 'order' option for this purpose.
Soring in ascending order
$model = $client->model('Lead');
$fields = ['first_name', 'last_name'];
$result = $model->getList(['fields' => $fields, 'order' => 'last_name'], 0, 3);
printf("There are %d leads in total\n", $result->totalResults());
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT), "\n";
Output:
1 There are 38 leads in total
5 "last_name": "Arriaga",
6 "id": "4da808b9-c6df-2407-9b0f-5aa798878d1d",
7 "name": "Alton Arriaga",
9 "_display": "Alton Arriaga"
12 "first_name": "Wilda",
14 "id": "438b96a9-2603-2854-681f-5aa798cdf157",
15 "name": "Wilda Bakke",
17 "_display": "Wilda Bakke"
20 "first_name": "Craig",
22 "id": "4b561e06-c3b2-c1f3-0dc3-5aa798663683",
23 "name": "Craig Bleau",
25 "_display": "Craig Bleau"
Soring in descending order
$model = $client->model('Lead');
$fields = ['first_name', 'last_name'];
$result = $model->getList(['fields' => $fields, 'order' => 'last_name desc'], 0, 3);
printf("There are %d leads in total\n", $result->totalResults());
echo json_encode($result->getRecords(), JSON_PRETTY_PRINT), "\n";
Output:
3 "first_name": "Angelo",
4 "last_name": "Winston",
5 "id": "dc3c817d-49e1-a0d5-ecbf-5aa798bf8354",
6 "name": "Angelo Winston",
8 "_display": "Angelo Winston"
11 "first_name": "Michael",
12 "last_name": "Whitehead",
13 "id": "d341cb27-683b-3d9f-9554-5aa798b475f0",
14 "name": "Michael Whitehead",
16 "_display": "Michael Whitehead"
19 "first_name": "Maximo",
20 "last_name": "Spradlin",
21 "id": "43950469-288d-6250-713f-5aa798bd0dd1",
22 "name": "Maximo Spradlin",
24 "_display": "Maximo Spradlin"