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 is
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 = 0){
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
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 4/10/01 -0700,
: [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 (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional
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, but shouldnt this
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
7 matches
Mail list logo