Hi,
I'm trying to better understand the if statement.
I know that you can set variabes in an if statement, eg if ($foo = bar()), then do something with $foo. But how does this work in relation to compound if statements.
Take the code below for example:
This returns:
1 ... bar
So it seams that the value assigned to $a is not available to the f2() function, and becomes simply "1" (True?) after the if statement is finished.
I was wondering if there's a way of making something like this work without using nested if statements?
thanks
--chris
I'm trying to better understand the if statement.
I know that you can set variabes in an if statement, eg if ($foo = bar()), then do something with $foo. But how does this work in relation to compound if statements.
Take the code below for example:
Code:
<?php
function f1 () {
return "foo";
}
function f2 ($foo) {
return $foo . "bar";
}
if ($a = f1() && $b = f2($a)) {
echo "$a ... $b<br />\n";
}
?>
This returns:
1 ... bar
So it seams that the value assigned to $a is not available to the f2() function, and becomes simply "1" (True?) after the if statement is finished.
I was wondering if there's a way of making something like this work without using nested if statements?
thanks
--chris