显示所有数组内容

时间:2015-11-20 06:02:34

标签: php

我有问题将值$word作为数组赋值,以便我可以将其作为变量。

我正在显示输出 1,000,000,000他们有不同的回声;我想把它们作为1个值的例子:

$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);
}

非常感谢。

1 个答案:

答案 0 :(得分:0)

您不需要制作任何自定义功能,只需使用number_formatexplode功能即可

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

Demo