title: Laravel Foreach From Array
body: <p>Here is the <code>print_r</code> of my object;</p>
  
  <pre><code>Array
  (
  [country] =&gt; Illuminate\Database\Eloquent\Collection Object
      (
          [items:protected] =&gt; Array
              (
                  [0] =&gt; App\Models\Location Object
                      (
                          [connection:protected] =&gt; 
                          [table:protected] =&gt; 
                          [primaryKey:protected] =&gt; id
                          [perPage:protected] =&gt; 15
                          [incrementing] =&gt; 1
                          [timestamps] =&gt; 1
                          [attributes:protected] =&gt; Array
                              (
                                  [country] =&gt; Scotland
                              )
  
                          [original:protected] =&gt; Array
                              (
                                  [country] =&gt; Scotland
                              )
  
                          [relations:protected] =&gt; Array
                              (
                              )
  
                          [hidden:protected] =&gt; Array
                              (
                              )
  
                          [visible:protected] =&gt; Array
                              (
                              )
  
                          [appends:protected] =&gt; Array
                              (
                              )
  
                          [fillable:protected] =&gt; Array
                              (
                              )
  
                          [guarded:protected] =&gt; Array
                              (
                                  [0] =&gt; *
                              )
  
                          [dates:protected] =&gt; Array
                              (
                              )
  
                          [casts:protected] =&gt; Array
                              (
                              )
  
                          [touches:protected] =&gt; Array
                              (
                              )
  
                          [observables:protected] =&gt; Array
                              (
                              )
  
                          [with:protected] =&gt; Array
                              (
                              )
  
                          [morphClass:protected] =&gt; 
                          [exists] =&gt; 1
                      )
  
                  [1] =&gt; App\Models\Location Object
                      (
                          [connection:protected] =&gt; 
                          [table:protected] =&gt; 
                          [primaryKey:protected] =&gt; id
                          [perPage:protected] =&gt; 15
                          [incrementing] =&gt; 1
                          [timestamps] =&gt; 1
                          [attributes:protected] =&gt; Array
                              (
                                  [country] =&gt; England
                              )
  
                          [original:protected] =&gt; Array
                              (
                                  [country] =&gt; England
                              )
  
                          [relations:protected] =&gt; Array
                              (
                              )
  
                          [hidden:protected] =&gt; Array
                              (
                              )
  
                          [visible:protected] =&gt; Array
                              (
                              )
  
                          [appends:protected] =&gt; Array
                              (
                              )
  
                          [fillable:protected] =&gt; Array
                              (
                              )
  
                          [guarded:protected] =&gt; Array
                              (
                                  [0] =&gt; *
                              )
  
                          [dates:protected] =&gt; Array
                              (
                              )
  
                          [casts:protected] =&gt; Array
                              (
                              )
  
                          [touches:protected] =&gt; Array
                              (
                              )
  
                          [observables:protected] =&gt; Array
                              (
                              )
  
                          [with:protected] =&gt; Array
                              (
                              )
  
                          [morphClass:protected] =&gt; 
                          [exists] =&gt; 1
                      )
  
                  [2] =&gt; App\Models\Location Object
                      (
                          [connection:protected] =&gt; 
                          [table:protected] =&gt; 
                          [primaryKey:protected] =&gt; id
                          [perPage:protected] =&gt; 15
                          [incrementing] =&gt; 1
                          [timestamps] =&gt; 1
                          [attributes:protected] =&gt; Array
                              (
                                  [country] =&gt; Wales
                              )
  
                          [original:protected] =&gt; Array
                              (
                                  [country] =&gt; Wales
                              )
  
                          [relations:protected] =&gt; Array
                              (
                              )
  
                          [hidden:protected] =&gt; Array
                              (
                              )
  
                          [visible:protected] =&gt; Array
                              (
                              )
  
                          [appends:protected] =&gt; Array
                              (
                              )
  
                          [fillable:protected] =&gt; Array
                              (
                              )
  
                          [guarded:protected] =&gt; Array
                              (
                                  [0] =&gt; *
                              )
  
                          [dates:protected] =&gt; Array
                              (
                              )
  
                          [casts:protected] =&gt; Array
                              (
                              )
  
                          [touches:protected] =&gt; Array
                              (
                              )
  
                          [observables:protected] =&gt; Array
                              (
                              )
  
                          [with:protected] =&gt; Array
                              (
                              )
  
                          [morphClass:protected] =&gt; 
                          [exists] =&gt; 1
                      )
  
                  [3] =&gt; App\Models\Location Object
                      (
                          [connection:protected] =&gt; 
                          [table:protected] =&gt; 
                          [primaryKey:protected] =&gt; id
                          [perPage:protected] =&gt; 15
                          [incrementing] =&gt; 1
                          [timestamps] =&gt; 1
                          [attributes:protected] =&gt; Array
                              (
                                  [country] =&gt; 
                              )
  
                          [original:protected] =&gt; Array
                              (
                                  [country] =&gt; 
                              )
  
                          [relations:protected] =&gt; Array
                              (
                              )
  
                          [hidden:protected] =&gt; Array
                              (
                              )
  
                          [visible:protected] =&gt; Array
                              (
                              )
  
                          [appends:protected] =&gt; Array
                              (
                              )
  
                          [fillable:protected] =&gt; Array
                              (
                              )
  
                          [guarded:protected] =&gt; Array
                              (
                                  [0] =&gt; *
                              )
  
                          [dates:protected] =&gt; Array
                              (
                              )
  
                          [casts:protected] =&gt; Array
                              (
                              )
  
                          [touches:protected] =&gt; Array
                              (
                              )
  
                          [observables:protected] =&gt; Array
                              (
                              )
  
                          [with:protected] =&gt; Array
                              (
                              )
  
                          [morphClass:protected] =&gt; 
                          [exists] =&gt; 1
                      )
  
              )
  
      )
  )
  </code></pre>
  
  <p>I want a foreach loop to print out the three countries in the <code>country</code> array - (England, Wales, Scotland).</p>
  
  <p>I have tried loops such as;</p>
  
  <pre><code>@foreach ($locations['country'] as $country)
   {{ $country }}
  @endforeach
  </code></pre>
  
  <p>I have tried other variations of this but to no avail. What is the correct syntax? Also, can someone explain how I can interpret this so I can better understand foreach with arrays in future? I normally just end up guessing until I get the right result - but for a change I'd like to actually know how to put one together if that makes sense..</p>
  
  <p>I am using Laravel if it helps...</p>