|
|
Posted by Captain Paralytic on 11/28/07 10:35
On 28 Nov, 09:24, jodleren <sonn...@hot.ee> wrote:
> Hi!
>
> In while (false !== ($file = readdir($handle)))
>
> what happens?
> The $file gets assigned, and the value of that is compared with false?
> The assignment is being compared with false
>
> Say, I want to return true or an error code. Can I do;
>
> if($err = somefunc())
> echo "ok"
> else
> echo "error: $err";
>
> WBR
> Sonnich
if($err = somefunc())
echo "ok"
else
echo "error: $err";
may work.
An assignment "returns" the value that was assigned. This is why you
can do:
$a = $b = $c = 5;
and all 3 variables will have the value 5.
In your "if" comparison, any non-empty or non-zero value in the
brackets will be taken to be true.
So, if somefunc() returns 0 or nothing for a good result, then your
statement will do what you want.
Navigation:
[Reply to this message]
|