04-22-2008, 06:22 PM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Within a function you can return at any point.
PHP Code:
function check($value)
{
if (empty($value)) { dothis(); return; }
if (!ctype_alpha($value)) { dothis(); return; }
if (strcasecmp($value, $othervalue)) { dothis(); return; }
}
As for otherwise, what's the harm in using elseif to string your checks together? In other words, why is this (bearing in mind, it's not syntactically correct PHP):
PHP Code:
{
if (empty($value)) { dothis(); break; }
if (!ctype_alpha($value)) { dothis(); break; }
if (strcasecmp($value, $othervalue)) { dothis(); break; }
}
any prettier than:
PHP Code:
if (empty($value)) dothis();
elseif (!ctype_alpha($value)) dothat();
elseif (strcasecmp($value, $othervalue)) dothose();
If you absolutely insist in using break then you'll need to use some form of looping structure (to loop once) out of which you can break (note: not pretty!) :
PHP Code:
$foo = 'car';
do {
if ($foo === 'aar') { echo 'aar'; break; }
if ($foo === 'bar') { echo 'bar'; break; }
if ($foo === 'car') { echo 'car'; break; }
if ($foo === 'dar') { echo 'dar'; break; }
echo 'ear';
} while (0);
|
|
|
|