473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

comparison operator(output of the following program,and how it could be like that))

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $x='abcd';
  3. $y=0;
  4. if($x==$y){
  5. echo "pass";}
  6. else{
  7. echo "fail";}
  8. ?>
Sep 11 '13 #1
2 1045
i have tried it the output is pass but am not getting how it could be "pass".... i was expecting the output could be fail since $x and $y are not equal ......but the output is pass how it comes???? can anyone help me????
Sep 11 '13 #2
Rabbit
12,516 Expert Mod 8TB
It's because == is a loose comparison and will juggle data types. It will attempt to convert one data type to another before doing a comparison. In this case, the string is being parsed for a number, it finds no number, so it gets converted to the number 0. Hence, the pass.

If you want a strict comparison that compares values AND types, then you need to use ===.

More info can be found from the PHP manual here: http://www.php.net/manual/en/types.comparisons.php
Sep 11 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Ricky | last post by:
thanks for the replysir. i have made this code so far in declaring the NFA. In fact i do know what am i supposed to do , i just cant get it right. please have a look at the following code and tell...
3
by: Jason Heyes | last post by:
This is a revised version of a post entitled "Class to support keywords". Please reply to this post instead of the old one. The following program repeatedly prompts the user for C++ keywords...
6
by: PengYu.UT | last post by:
Hi, I run into error with the following program. Would you please help me? Best wishes, Peng struct tag1{}; struct tag2{};
2
by: William LaMartin | last post by:
I have created a program that allows for the automation of things in Word documents, like changing the values of DocVariables and the links to Excel Sheets. I did it using interoperoperatability,...
2
by: mikelinyoho | last post by:
Does the following program architecture make sense? #include <stdio.h> #include "test1.c" #include "sample.cpp" int main(void){ output();
9
by: gg | last post by:
If somebody asks me to write a program that prints itself ( quine ) can I write the following program as an answer - #include <iostream> #include <fstream> using namespace std; int main (...
0
by: joestevens232 | last post by:
I need some serious help...I got the first part of the program done the accountant part but i can't figure out how to do the checker..i have been trying for hours and nothings workin any help or...
10
by: sunny | last post by:
Does this following program implement the factory design.if not what are things that i have to change in order to make this following program to be designed to factory design pattern. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.