md语法快捷键_有用PHP语法快捷方式

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.

翻译自: https://thenewcode.com/369/Useful-PHP-Syntax-Shortcuts

md语法快捷键

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值