Exclamation Point meaning

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
Stela
Forum Commoner
Posts: 46
Joined: Tue Aug 12, 2008 12:38 pm

Exclamation Point meaning

Post by Stela »

Hello,

I know what this code is doing, but I cant understand the exclamation point.


<?php

$name1 = "John";
$name2 = "john";

$result = strcasecmp($name1, $name2);

if(!$result)
{
echo "They match!";
}

?>


Is it a special character?
Is it the same as "!=" ?

Thank you!
EducatedFool
Forum Newbie
Posts: 3
Joined: Tue Aug 12, 2008 1:00 pm

Re: Exclamation Point meaning

Post by EducatedFool »

int strcasecmp ( string $str1 , string $str2 )
Returns < 0 if str1 is less than str2 ; > 0 if str1 is greater than str2 , and 0 if they are equal.

in your case $result is 0 'cause they are equal.

!var means 'not'. So if $results != true or != 0.

true = 1
false = 0

I hope you understand what I'm saying.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Exclamation Point meaning

Post by califdon »

Stela wrote:Is it a special character?
Is it the same as "!=" ?
Yes. It reverses the meaning of whatever follows. That's not quite the same as != , which is a comparison operator.
Stela
Forum Commoner
Posts: 46
Joined: Tue Aug 12, 2008 12:38 pm

Re: Exclamation Point meaning

Post by Stela »

Now I get it :D

Just one more small question,

Does " ! " have a "group" name, like Wildcards, Comparison Operator?

I just wanna know if there are others like " ! " and were do I find them in the Manual.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Exclamation Point meaning

Post by califdon »

I suppose it would be called a negation operator.

Here's the official skinny:
http://us.php.net/manual/en/language.operators.php
Stela
Forum Commoner
Posts: 46
Joined: Tue Aug 12, 2008 12:38 pm

Re: Exclamation Point meaning

Post by Stela »

:mrgreen:
Post Reply