返回阵列的初始位置

时间:2016-09-30 08:23:52

标签: laravel blade laravel-blade

由于for循环,标题位于arrray的最后位置,但我希望数组在for循环结束后位于第1位

@foreach($title as $title)
<li><a href="{{url('page/'.$title->slug)}}">{{$title->slug}}</a></li>
@endforeach
<li><a href="{{ route('front.end',['slug'=>$title->slug])}}"><i class="fa fa-btn fa-sign-out"></i>FrontEnd</a></li>

1 个答案:

答案 0 :(得分:0)

尝试这样做

<?php $i=0; $first_slug="";?>
@foreach($all_title as $title)
  <?php 
    if($i == 0)
    {
      $first_slug = $title->slug;
    }
    $i++;
  ?>
  <li><a href="{{url('page/'.$title->slug)}}">{{$title->slug}}</a></li>
@endforeach
<li><a href="{{ route('front.end',['slug'=>$first_slug])}}"><i class="fa fa-btn fa-sign-out"></i>FrontEnd</a></li>