找到foreach中的第一个项目?

时间:2016-12-31 22:26:06

标签: php laravel if-statement foreach blade

我正在尝试添加类'active',如果这是foreach中的第一项,但我一直得到一个解析错误?我正在使用Laravel和Blade,这就是我传递$ members

的方式
let moveAction = SKAction.moveBy(x: 10, y: 0, duration: 2)
  

解析错误:语法错误,意外的'endforeach'(T_ENDFOREACH),   期待elseif(T_ELSEIF)或其他(T_ELSE)或endif(T_ENDIF)

public function getView()
    {
        Cache::remember('members.members', 1, function() {
            return Player::orderBy('id', 'DESC')->where('display_member', '=', '1')->limit(10)->get();
        });

        return view('frontend.members')->withMembers(Cache::get('members.members'));
    }

2 个答案:

答案 0 :(得分:2)

如果您的版本是laravel 5.3:

import _sqlite3,  time,  datetime, gpxpy.geo
conn = _sqlite3.connect('SpatialDB')
c = conn.cursor()

lat1 = -36.8090839
lon1 = 174.718904

c.execute('Select * FROM Media')
data = c.fetchall()
for row in data:
    lat2 = row[1]
    lon2 = row[2]
    busns= row[0]
    dist = gpxpy.geo.haversine_distance(lat1, lon1, lat2, lon2)/1000
    c.execute("UPDATE Media SET LastQueried = ?, Distance  = ? WHERE Business = ?",(Current_Timestamp,dist,busns))

conn.commit()
c.close()
conn.close()

答案 1 :(得分:0)

@foreach($array as $key => $value)
 @if ($key == 0)
    .....
 @endif
@endforeach