Re: Creating a more flexible function....
On 11/12/03 23:42, in article zd7Cb.476$iJ.413@newsfep1-gui.server.ntli.net,
"Ron" <Ron.Barnett@NTLWorld.com> wrote:
> when you call the fiunction you can omit say argument2
> as in
>
> $thing = myfunc ( 1,, "parameter 3 value")
>
> internally you just test for a false value for each parameter to see if it
> is absent.
>
> re-reading your message, you can always call a function with literal strings
> ("literal string" ) as a parameter just as i have done in the example above,
> If you want to take the passed strings and send them out as output, yes
> there is nothing wrong with that.
> just set up the function so that the appropriate string is returned at the
> end.
Ok, when I try to put a literal string into my fnction I get:
Missing argument 2 for telephone_check() in blah
Missing argument 3 for telephone_check() in blah
Missing argument 4 for telephone_check() in blah
So obviously I'm getting it wrong. It isn't recognising the strings I am
puttin I at positions 2,3,and 4 as corresponding to the variable positions
in my function as $empty, $wrong, $correct.
The code I'm using is...
$telephone_check = telephone_check($telephone, "Pease enter number", "Duff
number", "Looks good");
The function is:
function telephone_check($var, $empty, $wrong, $correct)
{
//check if variable exists
if (!$var)
{
return $empty;
}
elseif (!eregi("^[0-9\ \(\)\+\-]{10,}$",$var))
{
return $wrong;
}
else
{
return $correct;
}
}
So can anyone show me what I am doing wrong here. Is there some special
syntax I need to use when declaring the variable that says "I'll be putting
a string in this position?
|