开发者

How to rewrite this php more efficiently [closed]

开发者 https://www.devze.com 2023-04-08 22:36 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it开发者_如何学JAVA can be reopened, visit the help center. Closed 11 years ago.

I need to display manual/automatic transmission vehicle information, and the best I can come up with is the following code. I think its wrong and inefficient, but I can't quite put my finger on it.

<?php
if ($obj->AutoTrans == 'S'):
  echo "Automatic";
  if ($obj->ManualTrans == 'O'):
    echo " (Manual Optional)";
  endif;                   
elseif($obj->ManualTrans == 'S'):
  echo "Manual";
  if ($obj->AutoTrans == 'O'):
    echo " (Automatic Optional)";
  endif;     
endif;                  
?>


if ($obj->AutoTrans == 'S')
    echo "Automatic".($this->ManualTrans=='O'?' (Manual Optional)':'');

if ($obj->ManualTrans == 'S')
    echo "Manual".($this->AutoTrans=='O'?' (Automatic Optional)':'');


There's nothing inefficient about this method. You could write it cleaner (in my opinion) by using curly braces instead of using block syntax, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号