PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
blacksnday
Forum Contributor
Posts: 252 Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(
Post
by blacksnday » Fri Oct 07, 2005 5:17 pm
how can you have a variable/arg/etc that will be only used
if it has something defined for it?
Code: Select all
if($var1 == $var2)
{
echo "something";
}else{
echo "something else";
}
Where I would like the above IF ELSE to be used ONLY if
$var2 has something inside it.
Nathaniel
Forum Contributor
Posts: 396 Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA
Post
by Nathaniel » Fri Oct 07, 2005 5:23 pm
Code: Select all
if ( !empty($var2) )
{
if ( $var1 == $var2 )
{
//do something
}
else
{
//do something else
}
}
blacksnday
Forum Contributor
Posts: 252 Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(
Post
by blacksnday » Fri Oct 07, 2005 5:25 pm
doh! now that i look at that..... i slap myself !
thanks
Nathaniel
Forum Contributor
Posts: 396 Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA
Post
by Nathaniel » Fri Oct 07, 2005 5:33 pm
No problem.
elecktricity
Forum Contributor
Posts: 128 Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:
Post
by elecktricity » Sat Oct 08, 2005 12:38 am
I think this may work as well
Code: Select all
<?PHP
if($var1 == '' && $var1 == '')
{
//add stuff here
}
else
{
//add stuff here
}
?>
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Sat Oct 08, 2005 5:36 pm
empty also checks to see if the variable has been set, though. "if ($var == '')" will throw an error if it hasn't.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sat Oct 08, 2005 5:37 pm
i thought it threw a notice? oh wel.getting senile i guess..
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Oct 08, 2005 6:11 pm
it is a notice..
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Sat Oct 08, 2005 8:16 pm
A notice is a type of error. notice, warning, fatal, etc.
Notices just don't cause any real problems.