No announcement yet.

For Each Loop

  • Filter
  • Time
  • Show
Clear All
new posts

  • For Each Loop

    Hi guys, ive been stepping out of my comfort zone and learning something useful...Laravel and PHP...

    Welp, ive hit a wall and looking for some guideance on loops.

    im using a foreach statement to show a list of uploaded files wrapped in div's, i need a clear class adding after every fourth. This is what i have :

    @foreach ($files as $file) 
                                                                	@if ($i % 4 == 0) 
                                                                        <div class='clear'></div>
                                                                        {!! $i++; !!}
                                                                	<div class="col-md-4">
                                                                    	<img src="{!! asset($file) !!}" class="img-responsive profileMargintop">
    I have set variables at the top of the file, where $i = 0

    The result is the page showing a '0' then a clear class, then the foreach loop, without any other clear classes where they should be!

    Any ideas?

    Thanks in advance!

  • #2
    Well, I'm not privy to Laravel, but it appears the $i variable is not incrementing. Because using the modulus method, it will only increment if divisible by 4.
    Have a Script or Snippet you want to share?

    WWW Standards: HTML 4.01,
    HTML 5, CSS2.1, CSS3, XHTML 1.0
    PHP Standards: PHP Standards