PHP Variable Assignment Within If Statement
Sunday, June 7, 2009 - 11:43
The usual practice when checking for the return value of functions is to run the function and store the value in a variable, and then test that variable. Here is an example of that process using the strstr() function.
1 2 3 4 5 6 7 | $string = 'abcde'; $var = strstr($string, 'f'); if ( false !== $var ) { var_dump($var); } else { var_dump($var); } |
This code will output "bool(false)" as that was the return value of the strstr() function.