Hi there! I want to know if there is a cleaner solution for what I did. I needed to randomize an array in a model, so I did something like this at first:
shuffle($model->questions);
In this case, the model has a One to Many relation to a table named questions, making $model->questions an array to play with. I needed to randomize those questions in some specific case, like:
if($model->random_questions){
shuffle($model->questions);
}
But PHP throws an “Indirect modification of overloaded property “X” has no effect” error, supposedly because it can’t get the ->questions value, it gets only the reference, and shuffle can’t modify by reference (or so I understood). So what I did was:
if($model->random_questions){
$questions=$model->questions;
shuffle($questions);
$model->questions=$questions;
}
It works just fine, but I really don’t like the roundabout way of doing it. Is there a cleaner way to do it? Or some way to make shuffle work fine with $model->questions, like in my first example?