copy Copy chevron-down
Getting Started merge Echo & Printณัฐนนท์ ค่อมเสือ 620710309
➙ภาษา PHP จะมีการ output ค่าออกที่เป็นค่าพื้นฐานอยู่ด้วยกัน 2 วิธี คือ echo และ print 💪( ͡❛ ͜ʖ ͡❛҂)
echo จะมีการทำงานที่คล้ายกับ print ค่าพื้นฐานทั้ง 2 นี้สามารถใช้แทนกันได้และจะมีหน้าที่ไว้ใช่ส่งข้อมูลออกทางหน้าจอ ทั้ง 2 ค่านี้ไม่ได้เป็นฟังก์ชั้นแต่เป็นเพียงแค่โครงสร้าง จึงไม่จำเป็นต้องมี ( ) ก็ได้
➙ความแตกต่างของ echo และ print จะมีเพียงไม่กี่อย่างที่จะแตกต่างกันออกไป ( ͡°ω ͡°)
echo นั้นจะทำานเร็วกว่า print
echo จะไม่การคืนค่าใด แต่ print จะคืนค่าจำนวนเต็มเสมอหรือก็คือ 1
echo สามารถส่งค่า Argument(อาร์กิวเมนต์) ได้หลายตัว แต่ print ส่งได้แค่ 1 ตัวเท่านั้น
➻การใช้งาน echo / print ที่แสดงข้อความและเปรียบเทียบกับภาษาอื่นๆ ( ͡°Ɛ ͡° )
Copy <? php
echo " hello " ;
echo ( " world " );
?>
Copy <? php
print " hello " ;
print ( " world " );
?>
Copy public class Main {
public static void main ( String [] args ) {
System . out . println ( " Hello, World! " );
}
}
Copy print ( " Hello, World! " )
Copy # include < iostream >
using namespace std ;
int main () {
cout << " Hello, World! " << endl ;
}
Copy using System ;
class Program {
static void Main () {
Console . WriteLine ( " Hello, World! " );
}
} PHP : ที่ใช้ทั้ง echo และ print จะสามารถแสดงค่าออกมาได้เลย โดยที่มีหรือไม่มี ( ) ก็ได้
JAVA : จะใช้ System.out.println แทนในส่วนของ echo และ print
Python : จะไม่มี echo แต่จะใช้คำสั่ง print เพื่อ output ค่าได้เลย
C++ : ไม่มีทั้ง echo และ print จะใช้ cout <<"..."<< endl; แทน
C# : ใช้ Console.WriteLine แทน echo และ print
➻การเช็ค multiple arguments(หลายตัวแปร) ของ PHP และเปรียบเทียบกับภาษาอื่นๆ ( ͡°з ͡°)
Copy <? php
$ fname = " Gunjan " ;
$ lname = " Garg " ;
echo " My name is: " . $ fname ,$ lname ;
?>
Copy <? php
$ fname = " Gunjan " ;
$ lname = " Garg " ;
print " My name is: " . $ fname ,$ lname ;
?>
Copy public class Main {
public static void main ( String [] args ) {
String name1 = " Gunjan " ;
String name2 = " Garg " ;
System . out . println ( " Name: " + name1 + name2 );
}
}
Copy name1 = " Gunjan "
name2 = " Garg "
print ( " Name: " , name1 , name2 )
Copy # include < iostream >
using namespace std ;
int main () {
string name1 = " Gunjan " ;
string name2 = " Garg " ;
cout << " Name: " << name1 << name2 << endl ;
return 0 ;
} ➻ผลรับการแสดงค่าของ PHP และภาษาอื่นๆ (ᇴ‿ฺᇴ)
ERROR!
Parse error: syntax error, unexpected token "," in /tmp/KEu9xOiPrA.php on line 4
Name: Gunjan Garg
=== Code Execution Successful ===
Name: Gunjan Garg
=== Code Execution Successful ===
Name: Gunjan Garg
=== Code Execution Successful ===
Name: Gunjan Garg
=== Code Execution Successful ===
PHP : การใช้ echo ผลรับจะสามารถรันออกมาได้ เพราะการใช้ echo จะสามารถรับมาได้หลายค่าและยังรันได้ จะใช้เครื่องหมาย , ในการเชื่อม
PHP : ในส่วนของ print นั้นจะสามารถรับค่าได้แค่ค่าเดียวเท่านั้นโค้ดที่รันออกมาจึง Error
JAVA : จะสามารถ input และ output ได้หลายค่าและจะใช้เครื่องหมาย + ในการเชื่อมค่าที่กำหนดไว้
Python : จะใช้ , อยู่ละหว่าง output แต่ละอัน
C++ : จะใช้ เครื่องหมาย << เป็นการเชื่อมค่า output
C# : จะใช้การเชื่อมเหมือนกับ JAVA คือเครื่องหมาย +
➻การเช็ค return (❍ᴥ❍ʋ)
➻ผลรับของโค้ด ಠﭛಠ
ERROR!
Parse error: syntax error, unexpected token "echo" in /tmp/o6lqjYMpRh.php on line 3
PHP is a web development language.
Value return by print statement: 1
8
=== Code Execution Successful ===
Result of add function is 5
=== Code Execution Successful ===
Value of the data is: 3
=== Code Execution Successful ===
8
=== Code Execution Successful ===
PHP : ที่ใช้ echo ในการ return ค่านั้นไม่สาามารถทำได้ เนี่ยงจาก echo จะไม่มีการคืนค่า
PHP : ที่ใช้ print จะคืนค่า 1 ออกมา
JAVA : ในการที่จะใช้ return ต้องใช้ int char string แทนที่จะใช้ void หากใช้ void จะไม่มีการคืนค่าใดๆ
Python : เมื่อมีการใช้ return ฟังก์ชั้นทั้งหมดหลัง return จะหยุดทันทีและคืนค่าให้ผู้เรียก และถ้า return ไม่มีค่าก็จะส่ง none ไปให้ผู้ใช้ และสามารถคืนค่าหลายค่าพร้อมกันได้
C++ และ C# : จะเหมือนกับการใช้แบบ JAVA คือจะใช้ int char string แทน void เป็นต้น ก็จะสามารถคืนค่าได้
Echo / print : ทศพล ธนะทิพานนท์, & วราภรณ์ สุวรรณเวลา. (2552). PHP สำหรับงาน E-Commerce . สำนักพิมพ์วรรณิก.(ISBN(e-book) : 987-616-90224-1-1)
Echo / print : W3Schools. (n.d.). PHP echo and print statements . w3schoolsarrow-up-right
Echo / print : Javatpoint. (n.d.). PHP echo and print statements . javatpointarrow-up-right harrow-up-right
ตัวอย่างโค้ด PHP และคำอธิบาย:
GeeksforGeeks. (n.d.). PHP echo and print . geeksforgeeksarrow-up-right
Javatpoint. (n.d.). PHP echo and print statements . javatpointarrow-up-right
W3Schools. (n.d.). PHP echo and print statements . w3schoolsarrow-up-right
ตัวอย่างโค้ด Java และคำอธิบาย:
W3Schools. (n.d.). Java methods return . w3schoolsarrow-up-right
W3Schools. (n.d.). Java tutorial . w3schoolsarrow-up-right
ตัวอย่างโค้ด python และคำอธิบาย :
GeeksforGeeks. (n.d.). Python return statement . geeksforgeeksarrow-up-right
Real Python. (n.d.). Python return statement: Usage and best practices . realpythonarrow-up-right
W3Schools. (n.d.). Python variables - multiple assignment . w3schoolsarrow-up-right
ตัวอย่างโค้ด C++ และคำอธิบาย :
W3Schools. (n.d.). C++ variables . w3schoolsarrow-up-right
W3Schools. (n.d.). C++ function return . w3schoolsarrow-up-right
ตัวอย่างโค้ด C# และคำอธิบาย :
W3Schools. (n.d.). C# variables display. w3schoolsarrow-up-right
W3Schools. (n.d.). C# method parameters and return values . w3schoolsarrow-up-right