2013-03-27 173 views
1

我正在上一個Facebook應用程序,我試圖通過黃道帶標誌獲取用戶的朋友列表。然而,有些用戶在同一個標​​志上有20個朋友。其他50個等等,我想將結果限制爲10.我需要專家的一些建議。限制foreach結果

foreach($all_friends_profile as $profile) 
{ 
    $frzodie = star_sign($birthday); 
    $frname = $profile->name; 
    $frid = $profile->uid; 
    $comp = "<div class=\"mod_frm mod_frm_margin clearfix\"> 
    <div class=\"pic\"><img src=\"https://graph.facebook.com/".$frid."/picture/\"></div> 
    <div class=\"meta\">".$frname."</div> 
    <div class=\"uiButton uiButtonSpecial\">Share</div></div>"; 

    if (strpos($frzodie,$randZodie) !== false) 
    { 
    echo $comp; // **This must be limited to 10.** 
    } 
} 

回答

1
$count = 0; 
foreach(...) { 
    ... 
    $count++; 
    if($count >= 10) { 
     break; 
    } 
}