Advertisement

09.06.2008 at 01:23PM PDT, ID: 23709173 | Points: 50
[x]
Attachment Details

Equality between string and  0 is true.. why?

Asked by Atouray in PHP Scripting Language, PHP and Databases

Tags:

Hi,

I was playing with a code snippet from the PHP bible and found that I didn't understand why ($set_var == $never_set) is true in the following code snippet. I'm running it using the default setup of xammp lite.

Please explain and if you have any more examples of similar strange PHP behavior it would be useful.

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
<HTML>
<HEAD>
<TITLE>My first PHP program</TITLE>
</HEAD>
<BODY>
<?php
 
$set_var = 0;
 
print("set_var print value: $set_var<BR>");
 
$never_set= "sjsjsjsjsj";
 
print("never_set print value: $never_set<BR>");
 
if ($set_var == $never_set){
   print("set_var is equal to never_set!<BR>");
}
 
 
?>
</BODY>
</HTML>
 
Loading Advertisement...
 
[+][-]09.06.2008 at 01:30PM PDT, ID: 22408857

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2008 at 01:37PM PDT, ID: 22408880

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2008 at 01:37PM PDT, ID: 22408885

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2008 at 01:51PM PDT, ID: 22408935

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.06.2008 at 01:52PM PDT, ID: 22408942

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628