the !

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
epic
Forum Newbie
Posts: 9
Joined: Sun Jun 02, 2002 6:14 am

the !

Post by epic »

I was looking through some code recently trying to learn some more by reading some scripts when i came accross this

Code: Select all

if (!$slug) { $errorListї$count] = "Invalid entry: Slug"; $count++; }

if (!$content) { $errorListї$count] = "Invalid entry: Content"; $count++; }
i know htat it is just checking to see if the required feilds have content in them the main thing i was worrying about was. what is this part

Code: Select all

if (!$slug)
what is the ! doing? what does it represent?
shareme
Forum Newbie
Posts: 22
Joined: Sat Jun 29, 2002 4:50 pm

Re: the !

Post by shareme »

epic wrote:I was looking through some code recently trying to learn some more by reading some scripts when i came accross this

Code: Select all

if (!$slug) { $errorListї$count] = "Invalid entry: Slug"; $count++; }

if (!$content) { $errorListї$count] = "Invalid entry: Content"; $count++; }
i know htat it is just checking to see if the required feilds have content in them the main thing i was worrying about was. what is this part

Code: Select all

if (!$slug)
what is the ! doing? what does it represent?
I could answer this but damn I am on the floor laughing so damn hard..

ah okay enough laughing

gotto:

http://www.phpbuilder.net

and do search for ! on the manual pages..

and laern this little number...

the PHP Manual is your friedn don't ever code without your friend..
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

the "!" represents "not"

so

if(!$var)

means

if the variable "var" does not exist then ...


ps, shareme.. it was a perfectly good question, dont be an ass
epic
Forum Newbie
Posts: 9
Joined: Sun Jun 02, 2002 6:14 am

Post by epic »

cheers all..
Last edited by epic on Wed Jul 10, 2002 3:21 am, edited 1 time in total.
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

actually, the ! is more used to determine a condition as being true or false, and not existent or non-existent

Example:

Code: Select all

$done = false;

// since $done is false, this makes the condition true
// NOT FALSE == TRUE
if (!$done) {
   echo "We are not done yet!";   
}

// this is the same as if ($done) so the condition is false
// FALSE == FALSE
else {
   echo "We are done!";
}
So, since the $done is false, then "We are not done yet!". Change $done = true; and you'll see that "We are done!"
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To check to see if a variable wasn't set you'd use ! and isset() so:

Code: Select all

if (!isset($myvar)) {
Don't name call Epic, shareme did point you in the right direction (did you look in the manual before you asked the question?), he may not have done it in the nicest possible way but there's no need to call him a turd.

Mac
shareme
Forum Newbie
Posts: 22
Joined: Sat Jun 29, 2002 4:50 pm

Post by shareme »

twigletmac wrote:To check to see if a variable wasn't set you'd use ! and isset() so:

Code: Select all

if (!isset($myvar)) {
Don't name call Epic, shareme did point you in the right direction (did you look in the manual before you asked the question?), he may not have done it in the nicest possible way but there's no need to call him a turd.

Mac
I did not worry about the name calling..

I took epic:

i know htat it is just checking to see if the required feilds have content in them the main thing i was worrying about was. what is this part

to mean that he understood what he was reading logic and programming wise..and just did not realize either what he stated or something else and thats why I pointed him to the manual..

if he had stated that he did not undestand those lines of code I would have explained how they work..
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

twigletmac makes a good point. A lot of people do this sort of check:

Code: Select all

if ( empty($_POSTї'submit']) )
or this:

Code: Select all

if ( !$_POSTї'submit'] )
when they really mean this:

Code: Select all

if ( isset($_POSTї'submit']) )
Just for reference, if you want to check if something is set or not, use the isset() function.
Post Reply