PHP print語句

類似於PHP echo語句,PHP print是一個語言結構(因爲有返回值,可以認爲它是函數),所以也不需要使用括號和參數列表。 與echo不同,它總是返回1

PHP print的語法如下:

int print(string $arg)

PHP print語句可以用來打印字符串,多行字符串,轉義字符,變量,數組等。

PHP print:打印字符串

File: print1.php

<?php  
    print "Hello by PHP print ";  
    print ("Hello by PHP print()");  
?>

執行上面代碼得到以下結果 -

Hello by PHP print Hello by PHP print()

PHP print:打印多行字符串

File: print2.php

<?php  
    print "Hello by PHP print  
this is multi line  
text printed by   
PHP print statement  
";  
?>

執行上面代碼得到以下結果 -

Hello by PHP print this is multi line text printed by PHP print statement

PHP print:打印轉義字符

File: print3.php

<?php  
    print "Hello escape \"sequence\" characters by PHP print";  
?>

執行上面代碼得到以下結果 -

Hello escape "sequence" characters by PHP print

PHP print:打印變量值

File: print4.php

<?php  
    $msg="Hello print() in PHP";  
    print "Message is: $msg";   
?>

執行上面代碼得到以下結果 -

Message is: Hello print() in PHP