note 90226 deleted from function.substr by danbrown

From: Date: Sat, 11 Apr 2009 15:15:13 +0000
Subject: note 90226 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153088@lists.php.net to get a copy of this message
Note Submitter: sarayut_b at hotmail dot com ---- <?php function comma_in_number($a){ $start = 0; for($i =(strlen($a)-1); $i>-1; $i--){ if(substr($a,$i,1) == "."){$start = $i-1;} } $length = array(); $cnt = $start+1; while($cnt>=0){$cnt = $cnt-3; array_push($length,$cnt); } //var_dump($length); for($i =0; $i <=strlen($a); $i++){ if(in_array($i,$length) && $i !== 0 ){$new.= ",".substr($a,$i,1);} else {$new.= substr($a,$i,1);} } return $new; } $a = "129582527.36" $new = comma($a); echo $new; echo "<br>".$a; ?>

« previous php.notes (#153088) next »