ฟังก์ชัน print() ของ PHP
การประกาศและการใช้งาน
ฟังก์ชัน print() จะทำการออกสัญญาณสตริงหนึ่งหรือหลายอัน
หมายเหตุ:print() ฟังก์ชันไม่ได้เป็นฟังก์ชัน ดังนั้นคุณไม่จำเป็นต้องใช้กล่องเปิดปิดที่ฝั่งทางด้านหลัง
Tip:print() function is slower than echo() Slower.
Syntax
print(strings)
Parameters | Description |
---|---|
strings | Required. Send one or more strings to output. |
Technical details
Return value: | ยังเฉพาะ 1 |
PHP version: | 4+ |
ตัวอย่างเพิ่มเติม
ตัวอย่าง 1
การแสดงค่าตัวแปรข้อความ (str)
<?php $str = 'I love Shanghai!'; print $str; ?>
ตัวอย่าง 2
การแสดงค่าตัวแปรข้อความ (str) ซึ่งมีตารางหน้าเอชทีเอ็มแอล
<?php $str = 'I love Shanghai!'; print $str; print '<br>What a nice day!'; ?>
ตัวอย่าง 3
การเชื่อมต่อตัวแปรข้อความ
<?php $str1 = 'I love Shanghai!'; $str2='What a nice day!'; print $str1 . ' ' . $str2; ?>
ตัวอย่าง 4
การแสดงค่าของตัวแปรในแถว
<?php $age=array("Bill"=>"60"); print 'Bill Gates is ' . $age['Bill'] . ' years old.'; ?>
ตัวอย่าง 5
การแสดงข้อความ
<?php print 'This text' ครอบคลุมหลายช่อง lines."; ?>
ตัวอย่าง 6
ความแตกต่างระหว่างอักษรเรียงตัวอักษรเดี่ยวและอักษรเรียงตัวอักษรสองตัว อักษรเรียงตัวอักษรเดี่ยวจะแสดงชื่อตัวแปร ไม่ใช่ค่าตัวแปร
<?php $color = 'red'; print 'Roses are $color'; print '<br>'; print 'Roses are $color'; ?>