I need some help w/ range function:
Code: range(1,4)
Output:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
How can I get an output like:
Array
(
[01] => 01
[02] => 02
[03] => 03
[04] => 04
)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For the values, you could use a string instead. There is an example using
array_mapto help you, and also withsprintfto pad zeros:In older PHP versions you may need this:
Output:
Array
Demo: http://codepad.org/Ovx1VQDM
But Array keys are intended for use in your code only, even though you could use strings as keys, it would be better to stay with integers.