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.
精彩评论