如何在PHP中为每个对象排序
从一个数组中,我为每个条目启动一个带有数组参数的函数(来自facebook的好友)。函数返回0或大于0的数字。所以现在,它只是混合显示,但我希望它首先显示从函数中得到大于0的结果的所有条目,然后是所有,都是0。我不知道该怎么做 这是我当前的代码如何在PHP中为每个对象排序,php,facebook,sorting,for-loop,each,Php,Facebook,Sorting,For Loop,Each,从一个数组中,我为每个条目启动一个带有数组参数的函数(来自facebook的好友)。函数返回0或大于0的数字。所以现在,它只是混合显示,但我希望它首先显示从函数中得到大于0的结果的所有条目,然后是所有,都是0。我不知道该怎么做 这是我当前的代码 foreach ($friends as $key=>$value) { //removed unimportant things $friendresult = friendscore($id = $fva
foreach ($friends as $key=>$value) {
//removed unimportant things
$friendresult = friendscore($id = $fvalue[id]);
if ($friendresult == "0") {
echo '<li>';
echo '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<b>Invite</b>';
echo '</a>';
echo '</li>';
}
if ($friendresult !=="0"){
echo '<li>';
echo '<a class="box">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<div class="totaltext">Score:'.$friendresult. '</div>';
echo '</a>';
echo '</li>';
}}
foreach($friends as$key=>$value){
//删除不重要的东西
$friendresult=friendscore($id=$fvalue[id]);
如果($friendresult==“0”){
回音“”;
回声';
回音“ ”;
}
如果($friendresult!=“0”){
回音“”;
回声';
$friend.=' ';
}
如果($friendresult!=“0”){
$nofriend.='li>';
$nofriend.='';
$nofriend.='';
$nofriend.=''.$fvalue[name].';
$nofriend.='Score:'.$friendresult';
$nofriend.='';
$nofriend.='';
}
echo$friend.$nofriend;哪里定义了$fvalue?foreach应该引用$fvalue而不是$value吗?你确定
!=
不应该是!=
?如果你不知道代码可以正常工作,那么这些都不一样,但我只想对它进行排序。所以,也许在问题之后,将它添加到数组中?而!==和!=就是不一样如果它们不是来自同一类型,hat,!==也会返回false,对吗?
if ($friendresult == "0") {
$friend.= '<li>';
$friend.= '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
$friend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$friend.= '<label>' . $fvalue[name] . '</label>';
$friend.= '<b>Invite</b>';
$friend.= '</a>';
$friend.= '</li>';
}
if ($friendresult !="0"){
$nofriend.= '<li>';
$nofriend.= '<a class="box">';
$nofriend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$nofriend.= '<label>' . $fvalue[name] . '</label>';
$nofriend.= '<div class="totaltext">Score:'.$friendresult. '</div>';
$nofriend.= '</a>';
$nofriend.= '</li>';
}