当使用不带大括号的if-statements
时,不要缩进它们,如下所示:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
但我想缩进它们,如下所示:
if($i === $this->get_current_page())
$current_class = "class='current'";
else
$current_class = '';
我使用CTRL + Shift +F来缩进代码。
顺便说一句,我正在使用Eclipse进行PHP开发。
发布于 2011-07-08 08:55:49
只需添加大括号,这是很好的编码练习!
或者在以下情况下使用三元:
$current_class = ($i === $this->get_current_page()) ? "class='current'" : "");
发布于 2011-07-08 09:01:15
我给出了Java的答案,但我认为用"PHP“替换"Java”也应该是可行的:
Go to Window Preference (选择首选项并打开→窗口)
Code→>选择→→Java代码样式
编辑格式并查找需要更改的内容(缩进或其他内容)。
保存(如果您想保留它,则导出)
现在,CTRL+SHIFT+F
将按照您想要的方式缩进代码。
https://stackoverflow.com/questions/6621905
复制