Is there a way to limit the values of the parameters passed into a function? Say I have a function setServiceDay() that can only accept values 'Su','M','T','W','Tr','F','Sa'.
Is there a way to set it up so that values other than those can't be passed? Or am I best off just doing checking within the function with an if statement?
Limited values for a function's parameters?
Started by dprimedx, Aug 04 2009 04:55 PM
2 replies to this topic
#1
Posted 04 August 2009 - 04:55 PM
|
|
|
#2
Posted 04 August 2009 - 07:40 PM
It is not possible. Simply use:
function fun($param) {
$vals = array("Su", "M", "T", "W", "Tr", "F", "Sa");
if(!in_array($param, $vals)
return false;
//Continue Code Here
}
#3
Posted 04 August 2009 - 08:58 PM
John said:
It is not possible. Simply use:
function fun($param) {
$vals = array("Su", "M", "T", "W", "Tr", "F", "Sa");
if(!in_array($param, $vals)
return false;
//Continue Code Here
}Thanks. That's what I ended up using after posting earlier.


Sign In
Create Account


Back to top









