我试图在 php 中从 Facebook 获取我的电影的某个数字之后突破一个 foreach 循环。
我认为这是愚蠢的小事。这是我得到的:
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_movie_info = $facebook->api('/me/movies?fields=name,genre,release_date,picture,likes');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
//print_r($user_movie_info);
$numer_of_movies_allowed = 2;
$movie_counter = 0;
foreach($user_movie_info['data'] as $movie) {
if ($movie_counter === $number_of_movies_allowed ) {
break;
}
echo '<img src="' .$movie['picture']['data']['url']. '">';
echo $movie['name'];
echo $movie['release_date'];
echo $movie['genre'];
echo $movie['likes'];
echo "</br> </br>";
$movie_counter ++;
}
print ($movie_counter);
print ($numer_of_movies_allowed);
它不会在两部电影之后爆发,而是将它们全部展示出来。
如果我使用:
if ($movie_counter == $number_of_movies_allowed )
或者
if ((int)$movie_counter === (int)$number_of_movies_allowed )
根本没有电影放映。