monkey64 Posted August 15, 2009 Share Posted August 15, 2009 I'm a newbie and I'm trying to simplify my code. Instead of: echo "var is "; if ($var < 0) echo "negative"; else echo "positive"; I'm using this: echo "var is ".($var < 0 ? "negative" : "positive"); But, in this example, I want to simplify it in the same manner. if($finance > '2000') { $loan = $finance - 2000; $deposit = $loan; } else { $loan = $finance; $deposit = $finance / 10; // 10% of Discount Price } Thing is, in each condition, I have two variables. Can it be simplified? Quote Link to comment Share on other sites More sharing options...
Alex Posted August 15, 2009 Share Posted August 15, 2009 $loan = ($finance > '2000') ? $finance - 2000 : $finance; $deposit = ($finance > '2000') ? $loan : $finance / 10; Quote Link to comment Share on other sites More sharing options...
monkey64 Posted August 15, 2009 Author Share Posted August 15, 2009 Thanks for the quick reply. It worked fine. Would this be faster to execute than my original version? Quote Link to comment Share on other sites More sharing options...
Alex Posted August 15, 2009 Share Posted August 15, 2009 Any difference would be negligible. 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.