GD77 Posted May 3, 2013 Share Posted May 3, 2013 (edited) Hello:Is their a way to format range single digits?ex: $ar1 = range (1,14); will return array(1,2,3...) I need to append 0 to single digits to have 01,02... Thanks. Edited May 3, 2013 by GD77 Quote Link to comment https://forums.phpfreaks.com/topic/277595-range/ Share on other sites More sharing options...
litebearer Posted May 3, 2013 Share Posted May 3, 2013 Might look at this... http://snipplr.com/view/39009/ Quote Link to comment https://forums.phpfreaks.com/topic/277595-range/#findComment-1427982 Share on other sites More sharing options...
Solution GD77 Posted May 3, 2013 Author Solution Share Posted May 3, 2013 Thanks, and I've used sprintf which is better then strn_pad in this case just need it for single digits. function add_leading_zeros($array) { foreach($array as $key=>$value) { $array[$key] = sprintf("%02s",$value); } return $array; } print_r(add_leading_zeros(range(1,14))); Quote Link to comment https://forums.phpfreaks.com/topic/277595-range/#findComment-1427984 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.