The use of exclamation mark "!" in php

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
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

The use of exclamation mark "!" in php

Post by jamal »

Hi,
I am getting confused at times the way that the exclamation mark is used in php. Please can anyone tell me how the exclamation mark is used in php?? I mean something like if (!(.....){}
Thanks in advance.
Jamal
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

the exclamation mark is the negation operator. in negates a boolean value and in essence switches its value. so TRUE == !(FLASE)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To carry on from what mydimension said it is often used for things like -

Code: Select all

if (!is_dir($name)) {
which basically says check to see if this function is returning FALSE, or more specifically in this case that $name is not a directory.

Mac
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

well said mac, just at 1 in the morning, explaining something becomes tiresome :lol:
Post Reply