php學習日誌(3)-echo&print

來源:互聯網
上載者:User

標籤:

      在php中,結果輸出一共有兩種方式:echo和print,下面將對兩種方式做一個比較。

echo與print的區別:

  echo print
連續輸出字串 能連續輸出多個字串 只能輸出一個字串
傳回值 無 返回1
用法 echo或echo() print或print()

(1)echo能連續輸出多個字串,print只能輸出一個字串:

執行個體1:

<?php/*echo能連續輸出多個字串,print只能輸出一個字串*/echo "echo輸出一個字串:";echo "hello,world";  //echo輸出一個字串echo "<br/>";echo "echo輸出多個字串:";echo "hello,world","hello,php","hello,python";   //echo輸出多個字串echo "<br/>";print "print輸出一個字串:";print "hello,world";  //print輸出一個字串print "<br/>";/*start-【print連續輸出多個字串】-start*/
print "print輸出多個字串:";print "hello,world","hello,php","hello,python";  //print輸出多個字串,出錯提示:Parse error: syntax error, unexpected ‘,‘ in C:\Users\13842\PhpstormProjects\test\print&echo.php on line 14/*end-【print連續輸出多個字串】-end*/print "<br/>";?>

屏蔽【print連續輸出多個字串】的代碼,結果如下:

如果不屏蔽【print連續輸出多個字串】的代碼,出現錯誤(語法錯誤):

(2)echo無傳回值,print永遠返回1

<?php/*print返回1,echo無傳回值*/$print_value=print "hello,world<br/>";  //結果:hello,worldprint "傳回值為$print_value";   //結果:傳回值為1$echo_value=echo "hello,world<br/>";   //出現語法錯誤?>

(3)輸出方式,帶括弧和不帶括弧沒有什麼區別,這裡不做解釋。

 

 

Technorati 標籤: php,echo,print

php學習日誌(3)-echo&print

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.