echo和print語句,echoprint語句_PHP教程

來源:互聯網
上載者:User

echo和print語句,echoprint語句


在php中,有兩種基本的輸出方法:echo 和 print

echo 和 print 之間的差異:

  • echo——能夠輸出一個以上的字串,無傳回值
  • print——只能輸出一個字串,並始終傳回值為1

echo的語句:

echo是一個語言結構,有無括弧均可使用:echo 或echo();

例如:

顯示字串:

echo "

PHP is fun!

";

echo "Hello world!";

echo "計劃","學習","PHP";

?>

顯示變數:

$txt1 = "Learn PHP";

$txt2 = "***.com";

$cars = array("Volvo","BWM","AABB");

echo $txt1;

echo "
";

echo "Study PHP at $txt2";

echo "
";

echo "my car is a {$cars[0]}";

?>

print的語句:

print也是語言結構,有無括弧均可使用: print 或 print();

顯示字串:

print "

PHP is fun!

";

print ""Hello world!
";

print "I'm about to learn PHP!";

?>

顯示變數:

$txt1="Learn PHP";

$txt2="W3School.com.cn";

$cars=array("Volvo","BMW","SAAB");

print $txt1;

print "
";

print "Study PHP at $txt2";

print "My car is a {$cars[0]}";

?>

好了,暫時就這些了,想起來再補,歡迎廣大網友來噴!!!!!!

http://www.bkjia.com/PHPjc/1133564.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133564.htmlTechArticleecho和print語句,echoprint語句 在php中,有兩種基本的輸出方法:echo 和 print echo 和 print 之間的差異: 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.