GD77 Posted May 3, 2013 Share Posted May 3, 2013 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. 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/ Link to comment https://forums.phpfreaks.com/topic/277595-range/#findComment-1427982 Share on other sites More sharing options...
GD77 Posted May 3, 2013 Author 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))); Link to comment https://forums.phpfreaks.com/topic/277595-range/#findComment-1427984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.