PHP - Is There A Shorter Better Way Of Doing This?
Hi folks, just wondering if there is a quicker, shorter way of coding this:
Code: [Select] <p>Which of the following best describes your religion:<br> <select name="religious"> <option <?php if ($religious == 0) {echo 'selected="selected"';} ?> value="0">Non religious</option> <option <?php if ($religious == 1) {echo 'selected="selected"';} ?> value="1">Christianity</option> <option <?php if ($religious == 2) {echo 'selected="selected"';} ?> value="2">Hinduism</option> <option <?php if ($religious == 3) {echo 'selected="selected"';} ?> value="3">Buddhism</option> <option <?php if ($religious == 4) {echo 'selected="selected"';} ?> value="4">Chinese traditional religion</option> <option <?php if ($religious == 5) {echo 'selected="selected"';} ?> value="5">Judaism</option> <option <?php if ($religious == 6) {echo 'selected="selected"';} ?> value="6">Atheist</option> <option <?php if ($religious == 7) {echo 'selected="selected"';} ?> value="7">Other</option> </select></p> I have a page with a load of options and to go through all of these is making the code huge. Any quicker ways? Similar TutorialsI have such lines of code: $link["beF1LP"]="https://www.site.com"; $link["beN1LP"]="https://www.site.com"; I know I can simplify it like this: $link["beF1LP"]=$link["beN1LP"]="https://www.site.com"; But I wanted something like this: $link["be(F|N)1LP"]="https://www.site.com"; Which did not work. How do I get it working for the string inside the brackets and under the quotes while using OR and/or other operators?
Thank you |