|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-06-17 09:25 UTC] nickj-phpbugs at nickj dot org
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 09:00:01 2025 UTC |
Description: ------------ Suppose I want to build a string with fixed length (for whatever reason) by appending a number to a string. //I want strings like 'foo0001','foo0002','foo0010' etc for ($i=1;$i<1000;$i++) { $string = 'foo'.$i; } strval could be useful IF it accepted a second (int) parameter to tell it: "This number will have <int parameter> characters in string form,fill it to the left with zeroes" With this behaviour,this would work: for ($i=1;$i<1000;$i++) { $string = 'foo'.strval($i,4);//This would give me '0001' } What about floats? Another parameter. Explained by example: for ($i=1;$i<1000;$i++) { $string = 'foo'.strval($i,4,3);//This would give me '0001.000' } For completeness: $number = 123456789; $string = 'bignumber: '.strval($number,5); Will result in the string 'bignumber123456789', since I asked for less characters than the number has.