md语法快捷键
As a general rule, code is like writing: the more concise it is, the better. Fewer characters tend to mean lower errors, and fewer bugs. To this end, there are a few syntax shortcuts that are very useful.
通常,代码就像编写代码一样:越简洁越好。 更少的字符往往意味着更少的错误,更少的错误。 为此,有一些非常有用的语法快捷方式。
如果捷径-没有大括号 (if shortcut – no braces)
If your if statement has only one directive, like the following:
如果您的if语句只有一个指令,则如下所示:
if ($x) { echo “This directive”; }
You can drop the braces:
您可以删除花括号:
if ($x) echo “This directive”;
if-else快捷方式 (if-else shortcut)
You’re probably used to the long, formal version of the if-else statement in PHP:
您可能已经习惯了PHP中if-else语句的正式版本:
if ($x == 5) { $y = 3 } else { $y = 2 }
While there is nothing wrong with this statement, it’s more efficient to use the shortened version, using the ternary operator:
虽然此语句没有任何问题,但使用三元运算符使用缩短的版本会更有效:
($x == 5) ? $y = 3 : $y = 2;
回显快捷方式 (echo shortcut)
echo has a shortcut too, so long as the shortcut for the PHP tag itself is supported on the server. This is particularly useful if you are echoing out small snippets as variables. So rather than:
echo也有一个快捷方式,只要服务器上支持PHP标记本身的快捷方式即可。 如果您将小的代码段作为变量回显,则此功能特别有用。 因此,而不是:
You have chosen <?php echo $foo; ?> widgets.
You can use:
您可以使用:
You have chosen <?=$foo?> widgets.
md语法快捷键