I am using Cakephp and I would like to learn how to set a select with values from 1 to 100?
Please notice I prefer to use $this->Form->input if possible.
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.
TLDR:
Explanation:
PHP’s
rangecreates an array of numbers (or letters), which is what you want for your options. But if you userangeby itself, it creates:This would give you a dropdown of numbers, but the values will start with zero regardless of the displayed number – in this case, you’d end up with
array(0=>1, 1=>2 ...When you really want this:
By using
array_combinejust makes it so the first option has the same value as the displayed number.(obviously you can write this in 1 line – I just broke it up for ease of reading)