There is such code:
$sorted = [];
foreach ($elements as $element_index => $element) {
foreach ($element->locations as $location_index => $location) {
$to_push = $element;
if ($to_push->field_type === 1 or $to_push->field_type === 2 or $to_push->field_type === 4 or $to_push->field_type === 8) {
$to_push->text_format = $location->text_format;
}
$to_push->position = $location->position;
$sorted[$to_push->position->page][] = $to_push;
}
}
$elements is a model of Eloquent
The problem is that
$sorted[$to_push->position->page][] = $to_push;
And here, for example, we have two iterations for $element->locations where the page number will be the same
Then in the mountains we will have two of the same item equal to the last iteration.
The behavior is very strange, can't understand why it is happening already zadolbalsya to impose a dump from all sides. Inside iterations do different things, and $sorted the same.
$to_push->text_format = $location->text_format;
for example) , you need to rebuild the sort logic, as I think that the clone model is not the best idea - Wava_Berni commented on June 10th 19 at 14:53