Is it possible in php to return a value from a function?
eg. In VB it would be written like the below which would return True or False.
VB Code:
Function MyFunction() as Boolean 'do whatever inside function 'MyFunction = True 'or 'MyFunction = False
Printable View
Is it possible in php to return a value from a function?
eg. In VB it would be written like the below which would return True or False.
VB Code:
Function MyFunction() as Boolean 'do whatever inside function 'MyFunction = True 'or 'MyFunction = False
Yep it is:
PHP Code:<?php
function myFunc()
{
$foo = "yakbar";
if($foo == "foobar")
{
return $foo;
}
else
{
return false;
}
}
echo myFunc();
?>
Thanks {yak}. I knew there must have been a way :)
So would the below code work?
PHP Code:if (MyFunction() == "True") {
//Do this because the function returned True
}
else {
//Do this because the function returned False
}
EDIT: I played around with it and it does work.