Skip to content
Advertisement

Insert multiple items in Laravel Collection inside a php loop

Hi I am trying to insert multiple items into a laravel collection inside a php loop but only one is getting inserted (the last one), please help to insert all the values.

This array $some_array = array(); has values like 1,2,3,4

The loop is like

JavaScript

Output required

JavaScript

Advertisement

Answer

use collection class at the top of the page.as,

JavaScript
JavaScript

use this snippet. Let me know the results.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement