標籤:false syntax this cap const var int 自己 bar
初學者,被echo文法困擾,查看,求各位大神指點!!!
手冊上寫echo — 輸出一個或多個字串,而字串有單引號,雙引號以及定界符。
單引號只會輸出字元本身,雙引號會輸出變數,手冊上寫的已經很詳細了。
<?php
echo "Hello World";
echo "This spans
multiple lines. The newlines will be
output as well";
//
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
//
echo "Escaping characters is done \"Like this\".";
// 你可以在回聲語句裡面使用變數
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo"; // foo is foobar
// You can also use arrays
$baz = array("value" => "foo");
echo "this is {$baz[‘value‘]} !"; // this is foo !
// 使用單引號將列印變數名,而不是值
echo ‘foo is $foo‘; // foo is $foo
// 如果您沒有使用任何其他字元,您可以只返回變數
echo $foo; // foobar
echo $foo,$bar; // foobarbarbaz
// 字串可以作為多個參數單獨傳遞或串連在一起並作為一個參數傳遞
echo ‘This ‘, ‘string ‘, ‘was ‘, ‘made ‘, ‘with multiple parameters.‘, chr(10);
echo ‘This ‘ . ‘string ‘ . ‘was ‘ . ‘made ‘ . ‘with concatenation.‘ . "\n";
//
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;
// 因為回聲不象一個函數,下面的代碼是無效的。
($some_var) ? echo ‘true‘ : echo ‘false‘;
// 然而,下面的例子將工作:
($some_var) ? print ‘true‘ : print ‘false‘; // print is also a construct, but
// it behaves like a function, so
// it may be used in this context.
echo $some_var ? ‘true‘: ‘false‘; // changing the statement around
?>
我自己寫的代碼
echo "{$match[0][0]}"."\n"."{$match[0][1]}"."\n"."{$match[0][2]}"."\n"."{$match[0][3]}"."\n"."{$match[0][4]}";
echo "{$match[0][0]}","\n","{$match[0][1]}","\n","{$match[0][2]}","\n","{$match[0][3]}","\n","{$match[0][4]}";
//可見,不同的字元表變數可以用英文.|,隔開,在加上轉義符,這樣每輸出一個數組就換一行,要輸出數組的話,最好用大括弧包括。
只能作為連續字串輸出
echo ‘wo zai zhe‘."\n".‘huanhang‘;
php中echo簡單用法