Page 1 of 1
the !
Posted: Tue Jul 09, 2002 7:01 pm
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
what is the
! doing? what does it represent?
Re: the !
Posted: Tue Jul 09, 2002 7:15 pm
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
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..
Posted: Tue Jul 09, 2002 7:57 pm
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
Posted: Tue Jul 09, 2002 9:08 pm
by epic
cheers all..
Posted: Tue Jul 09, 2002 9:30 pm
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!"
Posted: Wed Jul 10, 2002 2:00 am
by twigletmac
To check to see if a variable wasn't set you'd use ! and isset() so:
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
Posted: Wed Jul 10, 2002 10:09 am
by shareme
twigletmac wrote:To check to see if a variable wasn't set you'd use ! and isset() so:
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..
Posted: Wed Jul 10, 2002 12:19 pm
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:
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.