1

重複の可能性:
連想配列を介したphpループ

$ friendsという名前の配列を出力する変数があり、その出力は次のようになります。

{
  "data": [
    {
      "name": "Penelope-ns-test",
      "category": "Community",
      "id": "187099821418102",
      "created_time": "2012-06-14T15:00:59+0000"
    },
    {
      "name": "Fabric",
      "category": "Computers/technology",
      "id": "194407767268061",
      "created_time": "2012-06-07T07:24:03+0000"
    },

等...

次のようなものを取得するには、ループを実行する必要があります:if friends [id] == 1203438484 {

}

そうしないと...

foreach($friends['data'] as $data){
                $fbid = $data['id'];
                $fbfriendlikes[$fbid]=$facebook->api('/'.$fbid.'/likes'); 
                $fbname = $data['name'];
                $path = $protocol . '://graph.facebook.com/' . $fbid . '/picture?type=' . $size;
                $image = theme('image', array('path' => $path, 'alt' => $fbname));
                $return .= '<div class="fimage">'.$image.'</div>';
                $link = '<a href="'.$protocol . '://www.facebook.com/profile.php?id='.$fbid.'" target="_blank">'.$fbname.'</a>';
                foreach ($fbfriendlikes["data"] as $fbfriendlikes) {
    if ($fbfriendlikes["id"] == 184759054887922) {

                $return .= '<div class="flink">'.$link.'</div>';
                break;
                }
                }
            }

コードを手伝ってもらえますか?ありがとう!

4

2 に答える 2

3
foreach ($friends["data"] as $friend) {
    if ($friend["id"] == 12345) {
        // Do something with $friend

        break;
    }
}
于 2012-06-25T18:16:45.240 に答える
2
foreach($array['data'] as $friend)
{
    if ($friend['id'] == 1203438484)
    {
        //do something
    }

}
于 2012-06-25T18:17:34.967 に答える