Shuffle Symfony entities I've got an object $contest which is a Symfony entity that has some other entities assigned. I can get them by $content-&gt;getEntries();. That will return an object with the lazyloaded db objects. I need to display them in a random order.

$tempEntries = $contest-&gt;getEntries();
$entries = array();
if (count($tempEntries)) {
    foreach ($tempEntries as $temp) {
        $entries[] = $temp;
    }
    shuffle($entries);
}


This is the code I use currently. I loop through all elements (if there are any) and then shuffle them. I feel like the looping through them is a wast of resources.

Any advice on how to improve this?
You don't need a temporary variable $tempEntries
You don't need to check if the array is empty, if the array is empty shuffle will just do nothing


The code you need may look like:

$entries = $contest-&gt;getEntries();
shuffle($entries);