elentz Posted May 3, 2018 Share Posted May 3, 2018 (edited) I am getting the following error "syntax error, unexpected '}'" I don't see the error, all the brackets are where they need to be aren't they? $remote = Yes; if ($remote == "Yes"){ $serverip == $serverwanip; } else { $serverip == $serverlocalip; } echo $serverip; There is no echo of $serverip Thanks for looking Edited May 3, 2018 by elentz Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 3, 2018 Share Posted May 3, 2018 You are doing comparisons instead of assignments Quote Link to comment Share on other sites More sharing options...
elentz Posted May 3, 2018 Author Share Posted May 3, 2018 ugh I see what you are saying now. How can I set the serverip to either of the other two variables depending on the condition? Quote Link to comment Share on other sites More sharing options...
elentz Posted May 3, 2018 Author Share Posted May 3, 2018 I figured it out, thanks for pointing that out to me. Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 3, 2018 Share Posted May 3, 2018 Just for the sake of posterity and future google results: Your code should have been: if ($remote == "Yes"){ $serverip = $serverwanip; } else { $serverip = $serverlocalip; } This is a common pattern, and many languages (PHP included) have the ternary operator to reduce this to one line. $serverip = ($remote == 'Yes') ? $serverwanip : serverlocalip; Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 3, 2018 Share Posted May 3, 2018 (edited) Just for the sake of posterity and future google results: Your code should have been: if ($remote == "Yes"){ $serverip = $serverwanip; } else { $serverip = $serverlocalip; } This is a common pattern, and many languages (PHP included) have the ternary operator to reduce this to one line. $serverip = ($remote == 'Yes') ? $serverwanip : serverlocalip; Yes. And you can go one further and use a Boolean value (i.e. True/False) for the $remote value. Shouldn't be using Yes/No anyway when you really want a Boolean. Then it becomes even simpler since no comparison is even needed: $remote = True; // or False $serverip = ($remote) ? $serverwanip : serverlocalip; Edited May 3, 2018 by Psycho 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.