0

I am trying to display a number that has the english comma separation.

This code gets the number of likes from multiple pages and displays them in a list ordered by number of facebook likes.

    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 />";
}

The code works fine, by the way I am not a coder, and am only just getting into it.

I was trying to add in something like

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

But of course I have no idea if I can do that or where to put it.

Can anyone help?

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 に答える