Unstoppable Domains โ€” Get your daily AI drops report

PHP help needed

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
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
•••
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
•••
I think he is right ;)
 
0
•••
yes he is
 
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
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back