Dan wrote:
>
> This confused me for awhile, because the single equal sign seemed to work
> for comparison, but created inexplicable errors in my programs. It seems
> strange to me that a successful variable value assignment does not return
> true.
>
> example:
>
>
> $shiny = 1;
> if($shiny
Hi,
Dan wrote:
> > > if($shiny = 0){
> > This does not compare anyting, it assigns 0 to $shiny
>
> yes i know, but shouldnt this operation return true?
No, it doesn't return true.
The "=" operator returns the value of the expression on its right hand side.
Therefore, the statement given above
Hello Dan,
Wednesday, April 11, 2001, 1:29:22 AM, you wrote:
>>
>> > if($shiny = 0){
>> This does not compare anyting, it assigns 0 to $shiny
D> yes i know, but shouldnt this operation return true?
No. This operator returns the value assigned (0 in this case, which is
false). This expression
> if($shiny = 0)
This line is the same as
if ((shiny = 0) == TRUE)
It's common error with PHP and C.
You could make use of this like
if ($fp = fopen($filename,'r'))
since this is the same as
if (($fp = fopen($filename,'r')) == TRUE)
code after this line is executed when fopen() success to
You are right, thank you.
> It looks to me like the value of an assignment is the value assigned, as
in
> Perl. But I don't know for sure, haven't come across this in the manual.
>
> Kirk
>
> > > > if($shiny = 0){
> > > This does not compare anyting, it assigns 0 to $shiny
> >
> > yes i know, bu
L PROTECTED]
> Subject: Re: [PHP] assignment operator works for comparison??
>
>
>
> >
> > > if($shiny = 0){
> > This does not compare anyting, it assigns 0 to $shiny
>
> yes i know, but shouldnt this operation return true?
--
PHP General Mailing List (
>
> > if($shiny = 0){
> This does not compare anyting, it assigns 0 to $shiny
yes i know, but shouldnt this operation return true?
>
> > echo( $shiny ) // this will return 0
> That's normal, you just assign 0 to it ;)
>
> = assignment operator
> == comparison operator
>
> py
>
>
> At 01:53 PM
> if($shiny = 0){
This does not compare anyting, it assigns 0 to $shiny
> echo( $shiny ) // this will return 0
That's normal, you just assign 0 to it ;)
= assignment operator
== comparison operator
py
At 01:53 PM 4/10/01 -0700, you wrote:
>This confused me for awhile, because the single eq
This confused me for awhile, because the single equal sign seemed to work
for comparison, but created inexplicable errors in my programs. It seems
strange to me that a successful variable value assignment does not return
true.
example:
--Dan
--
PHP General Mailing List (http://www.php.net
9 matches
Mail list logo