I know the title is not very clear so here it’s in code:
function output($selector){
$one = 1;
$two = 2;
$there = 3;
return ? //should return 1 without if or switch statement
}
echo output('one');
If this is possible, how?
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.
Use a variable variable by prefixing the
$selectorvariable with another$:Remember to do sanity checks and/or implement default values, so you don’t end up generating unnecessary undefined variable errors and such from within your function.