Monday, May 22, 2017

How to create an objects collection from two arrays in php?

I'm using Laravel and i have two arrays in a controller

$country_name=["italia", "japan", "congo", "uk"]
$country_capital=["roma", "tokyo", "kinshasa", "london"]

Please note that the position of the country name in $country_name array is the same as the corresponding capital in the $country_capital array.

From these two arrays, I'm looking for a way to create a collection of objects called $countries, so in my blade file I could be able to use it like this:

<ul>
    @foreach($countries as $country)
       <li> : </li>
    @endforeach
</ul>

If someone can help me with functions or steps to obtain $countries from the two given arrays



via Evrard-c

Advertisement