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? Link to comment https://forums.phpfreaks.com/topic/170376-php-shorthand/ 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; Link to comment https://forums.phpfreaks.com/topic/170376-php-shorthand/#findComment-898745 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? Link to comment https://forums.phpfreaks.com/topic/170376-php-shorthand/#findComment-898747 Share on other sites More sharing options...
Alex Posted August 15, 2009 Share Posted August 15, 2009 Any difference would be negligible. Link to comment https://forums.phpfreaks.com/topic/170376-php-shorthand/#findComment-898750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.