0

hi guys,

im trying to loop a variable using 00 format..

ex. 01,02,03,04.......31

im going to use this for my dropdown of date. thanks!

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by eXpertPHP
0

Use this code:

$a = array_map(create_function('$x', 'return sprintf("%02s", $x);'), range(1,31));
0

Perhaps for() and if () is much faster (optimize hosting resources) than array_map(), create_function(), range() and sprintf() from aquilax example.

for ($i = 1; $i <= 31; $i++) echo '<option value="'.($d = $i < 10 ? '0'.$i : ''.$i).'">'.$d.'</option>';

Edited by eXpertPHP: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.