此代码会导致图像在网站上循环显示。
$all_players = DB::table('example_players')->leftJoin('example_votes', 'example_votes.from_player_id', '=', 'example_players.id')
->select('example_players.id', 'example_players.name', 'example_players.display_name', 'example_players.role', 'example_players.picture', DB::raw("sum(case example_votes.vote when 'like' then 1 else 0 end) as nbr_votes"))
->orderBy('nbr_votes', 'desc')
->groupBy('example_players.id')
->get();
内容
但是如何打破这段代码,以便旋转图像的循环继续在网站的其他地方?
类似
<?php
$myImagesList = array (
'image1.png' ,
'image2.png' ,
'image3.png' ,
'image4.png' ,
'image5.png' ,
'image6.png' ,
'image7.png' ,
'image8.png' ,
'image9.png' ,
'image10.png'
);
shuffle ($myImagesList);
echo '<div style = "background: #0600ff" class = "div02">';
for ($i=0; $i<10; $i++) {
if ($i < 5) {
echo '' . $myImagesList[$i] . '';
}
if ($i == 5) {
echo '</div>';
echo '<div style = "background: #0600ff" class = "div02">';
}
if ($i > 5) {
echo '' . $myImagesList[$i] . '';
}
}
echo '</div>';
?>
答案 0 :(得分:0)
制作2个for
循环,并在第二个循环之间执行任何操作。
<?php
$myImagesList = array (
'image1.png' ,
'image2.png' ,
'image3.png' ,
'image4.png' ,
'image5.png' ,
'image6.png' ,
'image7.png' ,
'image8.png' ,
'image9.png' ,
'image10.png'
);
for ($i=0; $i<5; $i++) {
echo $myImagesList[$i] . "\n";
}
echo 'Start second loop' . "\n";
//note no reassignment of $i
for ($i; $i<10; $i++) {
echo $myImagesList[$i] . "\n";
}