0

我正在尝试显示一个以英文逗号分隔的数字。

此代码从多个页面获取喜欢的数量,并将它们显示在按 Facebook 喜欢数量排序的列表中。

    function array_sort($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
    foreach ($array as $k => $v) {
        if (is_array($v)) {
            foreach ($v as $k2 => $v2) {
                if ($k2 == $on) {
                    $sortable_array[$k] = $v2;
                }
            }
        } else {
            $sortable_array[$k] = $v;
        }
    }
switch ($order) {
        case SORT_ASC:
            asort($sortable_array);
        break;
        case SORT_DESC:
            arsort($sortable_array);
        break;
    }
    foreach ($sortable_array as $k => $v) {
        $new_array[$k] = $array[$k];
    }
}
return $new_array;
}
function getLikes($arr){
$urls = "";
// Add urls to check for likes
for($i = 0;$i < count($arr);$i++) {
    if($urls != "") $urls .= ",";
    $urls .= $arr[$i];
}
// Retreive info from Facebook 
$xml = simplexml_load_file("http://api.facebook.com/restserver.php?method=links.getStats&urls=" . $urls);
$likes = array();
// Loop through the result and populate an array with the likes
for ($i = 0;$i < count($arr);$i++) {
    $url = $xml->link_stat[$i]->url;                    
    $counts = (int)$xml->link_stat[$i]->like_count;         
    $likes[] = array('likes' => $counts,'url' => $url);
}   
return $likes;
}
$array = array("URL HERE","URL HERE");
$likes = getLikes($array);
$likes = array_sort($likes, 'likes', SORT_DESC);
$english_format_number = number_format($likes, 'likes');
foreach ($likes as $key => $val) {
echo "<li class='facebook'><div class='fb-page'><div class='rank'>" . $key . "</div>" . "<div class='thumb "  . $val['url'] . "'><div class='link'>" . $val['url'] . "</div></div>" . "<div class='likes'>" . $val['likes'] . "</div></div></li><br />";
}

代码工作正常,顺便说一句,我不是编码员,只是刚刚进入它。

我试图添加类似的东西

    $english_format_number = number_format($likes, 'likes');

但当然我不知道我是否可以这样做或将它放在哪里。

任何人都可以帮忙吗?

4

1 回答 1

2

您在 number_format 函数中使用了错误的参数。正确的格式是 number_format(number,decimals,decimalpoint,separator)。所以把你的代码改成

$english_format_number = number_format($likes, 0, ',', '.') . 'likes';
于 2013-08-28T06:01:37.777 回答