Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 06-18-2008, 01:43 PM   #1 (permalink)
 
Newb Techie

Join Date: Sep 2006

Posts: 27

bukwus is on a distinguished road

Default Basic PHP question

Hi

Is it alright to set a variable's value to nothing like this:

$variable == '';

Or is there some kind of place holder that needs to go there?

Many thanks
bukwus is offline  
Old 06-18-2008, 06:39 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,688

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Basic PHP question

That's fine, although you did it wrong.

It should be $variable = '';

== means "is it equal to ...", = means "assigned to ...".

Also, you could use the unset function.

unset($variable).

The first way, assigning it to '', means it is set but has no value. using unset() means it is not set, and has no value, so it's like you never used it in the first place.
__________________

Need website help? PM me!
CrazeD is offline  
Old 06-21-2008, 03:09 AM   #3 (permalink)
 
Newb Techie

Join Date: Jun 2008

Posts: 9

PHPisl33t is on a distinguished road

Send a message via AIM to PHPisl33t Send a message via MSN to PHPisl33t Send a message via Yahoo to PHPisl33t Send a message via Skype™ to PHPisl33t
Default Re: Basic PHP question

Or you can do
$variable = null;
Which by php.net standards is the correct way,
Info Here
But it is EXACTLY what unset(); does, it's according on which you prefer to do, also a variable with no value is also considered null so $var = 0.0; would still be null... so yeah that's the other method other then what crazeD said.
PHPisl33t is offline  
Old 06-21-2008, 07:06 AM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,688

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Basic PHP question

Quote:
Originally Posted by PHPisl33t View Post
so $var = 0.0; would still be null...
No, $var would have a value of 0
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to make a HomePage, basic question about developing mixpage65 Web Site Hosting / ISP Q & A 1 01-28-2008 04:04 PM
basic question taintedplay Computer Networking & Internet Access 3 12-11-2007 10:05 AM
New computer, tell me what you think! and one little question too rgoldberg1 Building, Buying, or Upgrading High Performance PC Systems 3 11-12-2007 10:19 PM
Basic Virus location question Haoming Virus - Spyware Protection / Detection 1 07-28-2007 08:53 AM
Remote file access w/ IP + PHP? thejeremy Programming Discussions 2 04-04-2007 05:24 PM