Closed Thread Icon

Preserved Topic: ISSET syntax (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=21128" title="Pages that link to Preserved Topic: ISSET syntax (Page 1 of 1)" rel="nofollow" >Preserved Topic: ISSET syntax <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-23-2002 18:08

In PHP, I have this line:

if (isset($row['cphone'])){
print "TEL;CELL;VOICE:" . $row[cphone] . $ender;
}

I have verified that $row['cphone'] is empty, but it still gets printed. $ender is set to either "\n" normally, or "<br />\n" if a variable is passed via the URL. Either way, I get the same problem - the ISSET thinks that $row['cphone'] is set to something.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-23-2002 18:40

Function isset() checks whether variable is initialize or not (initial value can be set to empty string, but the variable is then initialized an isset() function will return true). If you want to check whether variable is empty or not, use empty() function instead...


DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-23-2002 20:46

Kind of off topic, but, what's the difference between print and echo? Is there a benefit to using one over the other?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-24-2002 06:47

echo() can accept more than one parameter, while print() can't...

echo $var1, $var2, $var3;


lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-24-2002 08:52

Pug, I have made a handy function:

code:
// isset and not empty
function issne($var)
{
return (isset($var) && !empty($var)) ? true : false;
}



in your case you call it as:
if (issne(&$row['cphone']))
{
//whatever ...
}

don't forget to call with the '&' operator.

another variation of this function is this (which takes an array param or a single param as the previous one):

code:
function issne($var)
{
if (!is_array($var))
return isset($var) && !empty($var) ? true : false;
else
{
$cond = true;
foreach ($var as $key)
{
$cond = $cond && isset($key) && !empty($key);
}
}
return $cond ? 1 : 0;
}



if (issne(array(&$var1, &$var2))
{
//stuff here
}


DL, there has been lots of discussions about 'echo' v.s 'print' in addition to the calling methods as mr. Max said, it has been noted that 'echo' is faster than 'print'


//lallous

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-24-2002 14:18

Thanks Max / lallous.

« BackwardsOnwards »

Show Forum Drop Down Menu