Operators

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

out of curiosity

whats hte difference between

=
==
and
!= (ive never heard of this one)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please don't hijack other user's topics. I have split this into it's own as it is not related to the original topic in which it was posted.

= -> assignment operator:

Code: Select all

$i = 10;
sets the value of $i as 10.

== -> comparison operator:

Code: Select all

if ($i == 10) {
tests whether $i has a value of 10

!= -> comparison operator:

Code: Select all

if ($i != 10) {
tests whether $i is not equal to 10

For more information:
http://php.net/language.operators

Mac
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

sorry twig

thank you very much for the information though :oops:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

= is assignment operator, i.e. after such code is executed:

Code: Select all

$a=3;
variable $a will hold the value '3'
== is equality operator [bool]. It returns true if the both operands are equal and false otherwise.
!= is inequality operator [bool]. It returns false if the both operands are equal and true otherwise.

There are also exists === and !== ;)
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

this might sound really idiotic but what the hell is bool, i keep on seeing it in the manual, but luckily the functions i use, i have pretty much mastered.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

bool is stand for boolean. It's datatype for logical values (either true or false).
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

ah, right, i understand now

but now another question

twiglet or no-one else has mentioned another type that i have just seen in a script on these forums
!==

is this the opposite of == (but then again, they are used in different situations) :?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

there are some other operators

=== checks whether values are equal or are the same type

Code: Select all

$a = 2; //Integer
$b = "2"; //String

if($a === $b) {
   //This would return false
}
!== means the values are not identical i.e. not the same value or data type

Mark
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Bech100 wrote: === checks whether values are equal or are the same type
Actually, "whether values are equal and are the same type".
Post Reply