Php 将数组与数据库中的数据进行比较

Php 将数组与数据库中的数据进行比较,php,arrays,Php,Arrays,我正在进行一个API调用,以获取我的朋友和为此获得的数组。我需要“过滤”在数据库中找到的ID所在的数组。现在结果只是“空” 这是数组(定义为变量$friends): 还有PHP代码,我想“过滤数据库中ID为的数组: $query_top_list_friends = mysql_query("SELECT * FROM ".$DBprefix."users WHERE center_id='" . $personal['center_id'] . "' ORDER BY

我正在进行一个API调用,以获取我的朋友和为此获得的数组。我需要“过滤”在数据库中找到的ID所在的数组。现在结果只是“空”

这是数组(定义为变量$friends):

还有PHP代码,我想“过滤数据库中ID为的数组:

$query_top_list_friends = mysql_query("SELECT * FROM ".$DBprefix."users 
          WHERE center_id='" . $personal['center_id'] . "' ORDER BY 
          workouts DESC LIMIT 10");
$i=0;                            

$friends = $friends['data'];

foreach($friends as $friend) 
{                        
    while ($top_list_friends = mysql_fetch_array($query_top_list_friends))
    {                    
       if($friend['id']==$top_list_friends['fid']) 
       {
         $i++;
         echo "<div class='user'>";
         echo "<span class='number'>" . $i . "</span>";
         echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
         echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
         echo "</div>";
       } 
    }  
}   
$query\u top\u list\u friends=mysql\u query(“从“$DBprefix.”用户中选择*
其中,中心id=““$personal['center\u id']”。”“订购人”
训练说明限制10“;
$i=0;
$friends=$friends['data'];
foreach($friends as$friend)
{                        
while($top\u list\u friends=mysql\u fetch\u array($query\u top\u list\u friends))
{                    
如果($friend['id']=$top\u list\u friends['fid']))
{
$i++;
回声“;
回音“$i”;
回显“$top_list_friends['name']”;
echo.“$top_list_friends['workouts'”;
回声“;
} 
}  
}   
有什么建议吗

更新

我对此做了一些更改,但仍然没有结果:

                $friends = array($friends['data']);

                while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {                    

                                if($friend[$top_list_friends['fid']]) {

                                $i++;
                                    echo "<div class='user'>";
                                    echo "<span class='number'>" . $i . "</span>";
                                    echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
                                    echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
                                    echo "</div>";
                                } 
                }       
$friends=array($friends['data']);
而($top\u list\u friends=mysql\u fetch\u数组($query\u top\u list\u friends)){
如果($friend[$top\u list\u friends['fid']])){
$i++;
回声“;
回音“$i”;
回显“$top_list_friends['name']”;
echo.“$top_list_friends['workouts'”;
回声“;
} 
}       

尝试如下更改$friends数组:

$friends = array ("FRIEND_ID"=>"One friends name", "ANOTHER_FRIEND_ID"=>"Another friends name");
然后:

while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {                    

                if($friend[$top_list_friends['fid']]) {

                $i++;
                    echo "<div class='user'>";
                    echo "<span class='number'>" . $i . "</span>";
                    echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
                    echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
                    echo "</div>";
                } 
}
while($top\u list\u friends=mysql\u fetch\u数组($query\u top\u list\u friends)){
如果($friend[$top\u list\u friends['fid']])){
$i++;
回声“;
回音“$i”;
回显“$top_list_friends['name']”;
echo.“$top_list_friends['workouts'”;
回声“;
} 
}

如果没有foreach($friends as$friend)循环:)

首先使用print\r(top\u list\u friends)和print\r($friends['data'])进行调试,并将其粘贴到帖子中(如果可能的话),谢谢你的帮助,但我仍然没有得到任何结果。我根据你的回答更新了我的问题,但可能我做错了什么?
while ($top_list_friends = mysql_fetch_array($query_top_list_friends)) {                    

                if($friend[$top_list_friends['fid']]) {

                $i++;
                    echo "<div class='user'>";
                    echo "<span class='number'>" . $i . "</span>";
                    echo "<span class='name'>" . $top_list_friends['name'] . "</span>";
                    echo "<span class='workouts'>" . $top_list_friends['workouts'] . "</span>";
                    echo "</div>";
                } 
}