Example of options, note the empty() when using 0/1:
<?php var_dump(isset($_REQUEST['var'])); var_dump(empty($_REQUEST ['var'])); var_dump(array_key_exists('var', $_REQUEST));?>

http://localhost/
bool(false) bool(true) bool(false)

http://localhost/?var
bool(true) bool(true) bool(true)

http://localhost/?var=0
bool(true) bool(true) bool(true)

http://localhost/?var=1
bool(true) bool(false) bool(true)

- Jon

On May 18, 2007, at 10:05 AM, David Krings wrote:

Shadab Wadiwala wrote:
Hi !!
I want to know what's the difference between the functions ----
isset() and empty()
I referred the function reference on php.net, but still couldn't the exact answer to my query.
isset() checks if a key exists in a server array such as $_SESSION or $_POST regardless of the value, which can be NULL or an empty string. I never used empty(), but just by the name of it that function checks if the value of a given variable or array key is considered "nothing" for the respective variable type. I always check if something is set in $_SESSION or $_POST (I rarely use get) and then go with that value. In case it is not set I either set a known good default value or I set a value that is guaranteed to generate an obvious error (means a runtime error, crash, or such).

David
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to