QueenZ Posted August 16, 2008 Share Posted August 16, 2008 Hi guys! I have numbers like $number = 06; $number2 = 07; $number3 = 03; $number4 = 23; and i need to remove these zeros before numbers... but i don't know how.. please help.. Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/ Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 $number = (int)$number; Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618153 Share on other sites More sharing options...
QueenZ Posted August 16, 2008 Author Share Posted August 16, 2008 that worked great and i also need the reverse version... from.... 1 2 3 10 11 12 to.... 01 02 03 10 11 12 Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618160 Share on other sites More sharing options...
DeanWhitehouse Posted August 16, 2008 Share Posted August 16, 2008 can i ask why you are removing 0's and then wanting to put them back? Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618161 Share on other sites More sharing options...
QueenZ Posted August 16, 2008 Author Share Posted August 16, 2008 can i ask why you are removing 0's and then wanting to put them back? i don't want to remove then and then put them back.. these are 2 different arrays i'm working with.. from one i need to remove them and to another one i need to add them... Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618165 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 Using consistent array indexing actually helps you know... Anyway... if your indexes are within 01 to 99 then function addZero($number) { if ($number < 10) $number = "0".$number; return $number; } Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618172 Share on other sites More sharing options...
QueenZ Posted August 16, 2008 Author Share Posted August 16, 2008 Using consistent array indexing actually helps you know... Anyway... if your indexes are within 01 to 99 then function addZero($number) { if ($number < 10) $number = "0".$number; return $number; } right... but i think it's without "" as it's string... $number = 0 . $number Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618178 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 try and tell me if it works Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618183 Share on other sites More sharing options...
DeanWhitehouse Posted August 16, 2008 Share Posted August 16, 2008 for this, if it's in quotes or not wont effect it Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618185 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 Joys of dynamic typing... Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618192 Share on other sites More sharing options...
QueenZ Posted August 16, 2008 Author Share Posted August 16, 2008 of course it's working... =) Quote Link to comment https://forums.phpfreaks.com/topic/120003-converting-numbers/#findComment-618206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.