Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP help needed

SpaceshipSpaceship
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
10
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
i think for an equals check you need == instead of =

so

PHP:
if ($a == $b){
echo 'Print something';
}
 
0
Close
I think he is right ;)
 
0
Close
yes he is
 
0
Close
Yah == is equal != is not equal.
 
0
Close
"=" 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
Close
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
Close
im still trying to learn what the heck php is rofl
 
0
Close
0
Close
Thanks for the links James :)
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back