Orio Posted May 15, 2006 Share Posted May 15, 2006 Hello,Is there a diffrence between- $foo=$bar and $bar=$foo ?Lets take an example:[code]$foo=1;$bar=10;if($_POST['age']<20){$bar=$foo;}elseif($_POST['age']<50){$foo=$bar;}else{$foo=100; $bar=100;};[/code]Lets say $_POST['age] is smaller than 20. Will both vars will be equal 10? Or is it vice versa?Thanks,Orio. Quote Link to comment Share on other sites More sharing options...
alpine Posted May 15, 2006 Share Posted May 15, 2006 [code] $foo=1;$bar=10;if($_POST['age']<20){$bar=$foo; // $bar will be 1 that is the value of $foo}elseif($_POST['age']<50){$foo=$bar; // $foo will be 10 that is the value of $bar}else{$foo=100; $bar=100;}[/code] Quote Link to comment Share on other sites More sharing options...
_will Posted May 15, 2006 Share Posted May 15, 2006 Both variables will be '1'. It will execute the first IF statement, and then exit the conditional, so $foo = 1 and $bar = 1. Quote Link to comment Share on other sites More sharing options...
Orio Posted May 15, 2006 Author Share Posted May 15, 2006 Thanks alpine [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]But what about varibles that weren't set?Another example:[code]$var=1;if(!isset($age)){$var=$age;echo($age);};[/code]Will any error occur? And is $var's value going to stay 1?Thx again,Orio. Quote Link to comment Share on other sites More sharing options...
_will Posted May 15, 2006 Share Posted May 15, 2006 [!--quoteo(post=374067:date=May 15 2006, 01:05 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ May 15 2006, 01:05 PM) [snapback]374067[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks alpine [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]But what about varibles that weren't set?Another example:[code]$var=1;if(!isset($age)){$var=$age;echo($age);};[/code]Will any error occur? And is $var's value going to stay 1?Thx again,Orio.[/quote]Why don't you test the PHP code you put up? You could put that in a test page and echo the output to see if it behaves the way you think it will. It probably would have taken less time than it would to post to the forum. Quote Link to comment Share on other sites More sharing options...
alpine Posted May 15, 2006 Share Posted May 15, 2006 [!--quoteo(post=374067:date=May 15 2006, 12:05 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ May 15 2006, 12:05 PM) [snapback]374067[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks alpine [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]But what about varibles that weren't set?Another example:[code]$var=1;if(!isset($age)){$var=$age;echo($age);};[/code]Will any error occur? And is $var's value going to stay 1?Thx again,Orio.[/quote]First off, your code here isn't logical because you are setting $var to be $age only when $age don't exist - so it would never echo anythinga variable that don't exist (isn't set) won't echo anything[code]$age = $_GET['age'];$var = 1;if(empty($age)){$age = $var;}echo $age; // prints out 1 if $age is empty, else it will echo whatever $age contains[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.