Javascript和PHP函数错误[关闭]

I have some problem with one of the functions from my code after I decided to mix my javascript code with PHP website, most of it works I just have problem with one function after I figured out which one was that.

Making the story short, can someone help me to fix this function that it will work on my PHP:

function Fix(what)
{
    var str='';
    what=Math.floor(what);
    what=(what+'').split('').reverse();
    for (var i in what)
    {
        if (i%3==0 && i>0) str=','+str;
        str=what[i]+str;
    }
    return str;
}

This function normally is working, but after I started using it on PHP instead of doing anything it shows me this:

<p id="add">function (a){this.push.apply(this,a);return this;}function (d){if(this.length<3){return null;}if(this.length==4&&this[3]==0&&!d){return"transparent"; }var b=[];for(var a=0;a<3;a++){var c=(this[a]-0).toString(16);b.push((c.length==1)?"0"+c:c);}return(d)?b:"#"+b.join("");}function (b){if(this.length!=3){return null; }var a=this.map(function(c){if(c.length==1){c+=c;}return c.toInt(16);});return(b)?a:"rgb("+a+")";}function (){for(var b=0,a=this.length;b</p>

The point of that function is to beautify the output for example instead of 1000 it shows 1,000 etc. but it looks like on PHP the code is lost somewhere in between. For example I want to use it this way: "document.getElementById("add").innerHTML=Fix(a);". The code I have in .js file, I just include it in my other .php files

There is a PHP method existing for that and is called number_format.

string number_format ( float $number , int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )

Doc is here http://php.net/manual/en/function.number-format.php