php中echo簡單用法

來源:互聯網
上載者:User

標籤: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簡單用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.