alexweber15 Posted October 6, 2008 Share Posted October 6, 2008 having 2 issues here can someone plz help me out? 1- if(condition){ return $variable1; } else { return $variable 2;} how can i write this as a ternary statement? return condition ? $variable1 : $variable2; doesnt work and neither does this: condition? return $variable1 : return $variable2; and most importantly: 2- if($this->settings['stickyID']){ $this->settings['id'] = &$this->settings['name']; }else{ $this->settings['id'] = $this->settings['name']; } i wanted to rewrite this as: (stickyID is bool btw) $this->settings['id'] = $this->settings['stickyID'] ? &$this->settings['name'] : $this->settings['name']; much simpler right? i get an error with the & though.... thanks! Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 return (condition) ? $var1 : $var2; should work As for the reference, the & goes with the =, not the variable when assigning.. so should probably use an if statement there. edit: nevermind about the other example I gave, it won't work Quote Link to comment Share on other sites More sharing options...
alexweber15 Posted October 6, 2008 Author Share Posted October 6, 2008 return (condition) ? $var1 : $var2; should work As for the reference, the & goes with the =, not the variable when assigning.. so should probably use an if statement there. edit: nevermind about the other example I gave, it won't work funny thing is the first example works in javascript if im not mistaken... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 return (condition) ? TRUE_VAR : FALSE_VAR works for me, so why don't you show us what you actually tried, instead of: return condition ? $variable1 : $variable2; Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 Yeah, when I said it should work, I should have been distinct and said it does work. 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.