I know that we can randomly sort a DataList
with the following:
$example = Example::get()->sort('RAND()');
But when I try to randomly sort an ArrayList
it doesn't work. I can sort an ArrayList
by ID DESC
, but not with RAND()
.
Is there a way to make an ArrayList
randomly sort its items?
Example:
public function AllTheKits() {
$kits = Versioned::get_by_stage('KitsPage', 'Live');
$kitsArrayList = ArrayList::create();
foreach ($kits as $kit) {
if ($kit->MemberID == Member::currentUserID()) {
$kitsArrayList->push($kit);
}
}
return $kitsArrayList;
}
In a page:
public function getKitsRandom() {
return $this->AllTheKits()->sort('RAND()');
}
This does not work in a template with <% loop KitsRandom %>