回声格式Q. [英] echo format Q
问题描述
不相关的问题时间,可能是:
是否有任何优势/理由使用一种格式而不是另一种格式
跟随两种类型的echo语句?
1. echo" error is" 。 $ error;
2. echo" error is $ error";
显然我说的是比上面的例子更长的陈述,
但他们确实创造了相同的输出。
第1行是我找到的大部分代码片段/样本的编写方式。
但是第2行打字少了很多,至少对我来说,更容易保持
跟踪。
也许这是我的经验不足,但是只有我看到
.... 。 concatenator很有用,如果我想打印类似
" $ error is 0" ;;然后它只是回声''$ error is'。 $错误;但是,总是还有其他方法可以实现它,我并不是说这需要
才能进入这里。
如果你认为这浪费你的时间,那好吧;我明白。但是如果
有意见我会有兴趣听听是否有任何优势
。大多数情况下,如果我没有别的话,我会选择首选的习惯。
TIA,
Twayne
Hi,
Irrelevant question time, probably:
Is there any advantage/reason to use one format over the other for the
following two types of echo statements?
1. echo "error is " . $error;
2. echo "error is $error";
Obviously I''m talking about longer statements than the samples above,
but they do create identical outputs.
Line 1 is how most of the code snippets/samples I find are written.
But line 2 is a lot less typing and for me at least, easier to keep
track of.
Maybe it''s my gross inexperience showing but the only time I see the
...." . concatenator useful is if I want to print something like
"$error is 0"; then it''s just echo ''$error is '' . $error; but as
always, there are still other ways to accomplish it, which I didn''t mean
to get into here.
If you consider this a waste of your time, OK; I understand. But if
have an opinion I''d be interested to hear whether there is any advantage
of one over the other. Mostly, so that I pick up the preferred habit if
nothing else.
TIA,
Twayne
推荐答案
错误;
2. echo"错误是
error;
2. echo "error is
错误" ;
显然我说的是比上面的样本更长的陈述,
但他们确实创造了相同的输出。
第1行是我找到的大部分代码片段/样本的写法。
但是第2行打字要少得多,至少对我来说,更容易保持
跟踪。
也许这是我的经验不足,但我唯一一次看到
.... 。 concatenator有用的是,如果我想打印类似
"
error";
Obviously I''m talking about longer statements than the samples above,
but they do create identical outputs.
Line 1 is how most of the code snippets/samples I find are written.
But line 2 is a lot less typing and for me at least, easier to keep
track of.
Maybe it''s my gross inexperience showing but the only time I see the
...." . concatenator useful is if I want to print something like
"
error is 0" ;;然后它只是回声''
error is 0"; then it''s just echo ''
这篇关于回声格式Q.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!