Current location: Hot Scripts Forums » Programming Languages » PHP » if(!$a=="") Means?


if(!$a=="") Means?

Reply
  #1 (permalink)  
Old 12-14-04, 06:22 AM
steveo steveo is offline
Wannabe Coder
 
Join Date: Jun 2004
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
if(!$a=="") Means?

This may sound stupid, but what does the following snippet of code actually mean/do?

PHP Code:

if(!$a==""
I've experimented and I know how it works, but I'm not sure if I'm right about what it does, could anyone just clarify what it does?
Reply With Quote
  #2 (permalink)  
Old 12-14-04, 06:36 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
if !empty() means, if not empty
if !isset() means if is not set.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #3 (permalink)  
Old 12-14-04, 07:12 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by steveo
This may sound stupid, but what does the following snippet of code actually mean/do?

PHP Code:

if(!$a==""
I've experimented and I know how it works, but I'm not sure if I'm right about what it does, could anyone just clarify what it does?
if variable a is not equal to ""
could also be written if ($a != "")

E: thats what i would say.. not sure tho
Reply With Quote
  #4 (permalink)  
Old 12-14-04, 07:22 AM
steveo steveo is offline
Wannabe Coder
 
Join Date: Jun 2004
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Thought so,
thanks.
Reply With Quote
  #5 (permalink)  
Old 12-14-04, 08:34 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Thats it Wille.

Could also be written:

If a is not empty
if !empty($a)
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #6 (permalink)  
Old 12-14-04, 11:01 PM
1jetsam 1jetsam is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
if (!$a == "") {

}
is the same as:
Code:
if (!$a == NULL) {

}
or
Code:
if (!($a)) {

}
Breaking it up. This part: $a=="" means If variable 'a' is equal to nothing (NULL), then...
and the ! means the opposite: If varaible 'a' does not equal nothing.
The last example I provided just means, (which is just another way to think of it): If variable 'a' is not set (if it is not assigned to anything...if it is equal to nothing, NULL)...
__________________
Quate CMS 0.3.3 Released - A simple, fast Content Management System.
Reply With Quote
  #7 (permalink)  
Old 12-15-04, 01:57 AM
okki okki is offline
New Member
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb splitting hairs

$a=""
means variable a is equal to an empty string, which is different from $a=NULL

!$a="" would be: $a is not an empty string or !empty($a)
wehre
!$a=NULL would be: $a is not NULL or !isset($a)

Correct me if I'm wrong but there is a difference and that difference has something to do with memory allocation.

Grz.
Reply With Quote
  #8 (permalink)  
Old 12-15-04, 03:23 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by okki
$a=""
means variable a is equal to an empty string, which is different from $a=NULL

!$a="" would be: $a is not an empty string or !empty($a)
wehre
!$a=NULL would be: $a is not NULL or !isset($a)

Correct me if I'm wrong but there is a difference and that difference has something to do with memory allocation.

Grz.
exactly my toughts
Reply With Quote
  #9 (permalink)  
Old 12-15-04, 05:29 AM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by <?Wille?>
exactly my toughts
Actually, don't ever use any of those first structures because they lack the double equals ==, therefore causing them to be treated as an instruction and always return positive (or negative if you use the exclamation mark)
Reply With Quote
  #10 (permalink)  
Old 12-15-04, 06:27 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
if ($a = "")
{
echo 'The variable \$a was set to ""';
}
..

Thats what happens if you use one equals sign..

If $x = this_condition
so, if $x was successfully set to the conditions value...
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What does icon with a red little square means? V@no Hot Scripts Forum Questions, Suggestions and Feedback 3 08-05-03 11:49 AM


All times are GMT -5. The time now is 05:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.