显示所有数组内容

I have problem assigning values to the $word as array so that I can make it as a variable.

I am displaying an output of 1,000,000,000 they have all different echos; I want to make them as 1 value only example:

$output = $arramt[1]="1",$arramt[2]="000",$arramt[3]="000",$arramt[4]="000"

function mnyFmt($word){
    $n = strlen($word);
    if ($n%3==0){
       $i = $n/3;
       $x=0;
       while($x<$i-1){
         echo substr($word,-$n,3).",";
         $arramt[$x] = substr($word,-$n,3).",";
         $x++;
         $n = $n-3;
      }
    echo substr($word,-$n,3);
    $arramt[$x] = substr($word,-$n,3).",";
    }
    elseif($n%3==1){

        $word1 = substr($word,1,$n);
        $w1 = strlen($word1);
        $i = $w1/3;
        echo substr($word,0,1).",";
        $x=0;
        while($x<$i-1){
           echo substr($word1,-$w1,3).",";
           $arramt[$x] = substr($word1,-$w1,3).",";
           $x++;
           $w1 = $w1-3;
      }
      echo substr($word1,-$w1,3);
      $arramt[$x] = substr($word1,-$w1,3).",";
      echo array_values($arramt[$x]);
  }
  elseif($n%3==2){
    $word1 = substr($word,2,$n);
    $w1 = strlen($word1);
    $i = $w1/3;
    echo substr($word,0,2).",";
    $x=0;
    while($x<$i-1){
       echo substr($word1,-$w1,3).",";
       $x++;
       $w1 = $w1-3;
    }
    echo substr($word1,-$w1,3);
    }
  }
  $amount = 1000000000;
  mnyFmt($amount);
}

Thanks very much in advance.

You don't need to make any of the custom function you can simply use number_format and explode function like as

$amount = 1000000000;
print_r(explode(',',number_format($amount)));

Demo