越简单越好!

数字三位加逗号

发表于 2006-11-23 10:53 | 561次阅读 0次点赞   PHP
<?php
function num3($num){
 preg_match_all("|[0-9]{1}|",$num,$getnum);
 $number = count($getnum[0])-1;
 $j = 1;
 $varchar = "";
 for($i=$number;$i>=0;$i--){
  if($j%3){
   $varchar = $getnum[0][$i].$varchar;
  }else{
   $varchar = $getnum[0][$i].$varchar;
   $varchar = ",".$varchar;
  }
  $j++;
 }
 return $varchar;
}
echo num3("1000221");
?>
返回顶部 ^