Skip to content

Instantly share code, notes, and snippets.

@m5lil
Created February 15, 2017 06:38
Show Gist options
  • Save m5lil/97f5199bea1c2d0731b61727456bcf14 to your computer and use it in GitHub Desktop.
Save m5lil/97f5199bea1c2d0731b61727456bcf14 to your computer and use it in GitHub Desktop.
loop two item in one row
<?php $c = 0; ?>

@foreach($products as $product)

  <?php $b = ( ++$c % 2 == 0 ) ? true : false; ?>
  
  @if($b)
    <div class="row ">
  @endif
      <div class="col-xs-12 col-sm-6 service_2i">
          <figure><img src="{{ url('/uploads') . '/' . $product->photo }}" alt="services" /></figure>
          <div class="service-two_content">
              <h6>{{ $product->name }}</h6>
              <p>{{ $product->content }}
              </p>
              <a href="{{url('/contact')}}" class="btn trans-btn service-btn ">إتصل بنا</a>
          </div>
      </div>  

  @if($b)
    </div>
  @endif

@endforeach

@MrShennawy
Copy link

MrShennawy commented Feb 15, 2017

another solution :)

$arr = ['a','b','c','d','f','g'];
$a = count($arr);
foreach ($arr as $value) {
	if($a % 2 == 0){
		echo $value;
	}else{
		echo $value."<br>";
	}
	$a--;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment