PHP的echo和print小談

來源:互聯網
上載者:User
自學php快2個多月了。學著做點東西,基本函數用的還湊合,用help點開加search找。基本沒問題
不過那個php首頁的說明實在是很模糊,很多參數說完了還是看不懂,有實踐才有真理。這點到哪裡都沒有錯。

碰到最初的就是echo和print的區別了,自己總結了下:

echo()和print()區別小談

同是字串輸出echo和echo、到底有啥區別尼?!!

PHP?言裡說,其實哪個都不算很嚴密。他們都可以不用括弧()而正常工作。
目前只發現3點比較大的區別。

1. echo()可以用逗號「,」分割?數字串, print()不可以

print " Hello " , " World " ; // syntax error。
echo " Hello " , " World " ; // syntax ok!!

※echo()用了括弧「()」以後,加逗號「,」區分?數字串也不行!請注意。

2. print()返回?果、 echo()卻不返回。

1 $output1 = print " Hello World " ; // 這個有輸出結果的
2 $output2 = echo " Hello World " ; // 這個卻沒有哦

3.如果不需要返回結果操作的話、echo()要稍微快一些。

echo ()vs print ()

Echoing 100000 of nothing
Exe Time is 0.034925937652588 secs .

Printing 100000 of nothing
Exe Time i s 0.037981986999512 secs .

這種差距你需要麼請自己判斷吧

  • 聯繫我們

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