Domain Empire

PHP help needed

Spaceship Spaceship
Watch
I'm trying to write this for one of my sites...
Anyways, I've never used PHP before, but I take programming at school so it's not really hard to understand...
I just have a little trouble with the syntax...
I'm just trying to do a simple if statement but it's not working for some reason. Here's what I have:

Code:
if ($a = $b){
echo 'Print something';
}

What is happening is that it always prints that out, even if a and b aren't equal.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
i think for an equals check you need == instead of =

so

PHP:
if ($a == $b){
echo 'Print something';
}
 
0
•••
0
•••
0
•••
Yah == is equal != is not equal.
 
0
•••
"=" is an asignment operator
Ex: $a = $b means that $a now contains whatever $b is.

"==" is the 'same as' comparison operator.
Ex: $a==$b means that $a is the same as $b.


The way you have your code written with the asignment operator is telling the parser to check that '$a contains $b', which will always prove true because you are not asking to compare the two but rather you are telling the parser that $a shall now contain the contents of $b.

With the comparison operator (==) you are asking the parser to compare the difference between the contents of two variables.

HTH
 
0
•••
Thank you. The problem was actually another one. I had tried it with one and 2 equal signs. But anyways, it's fixed now. :) Thank you.
 
0
•••
im still trying to learn what the heck php is rofl
 
0
•••
0
•••
Thanks for the links James :)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back