Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 2 of 13 · PHP Basics & Syntax
Interview question

What is the difference between echo and print in PHP? PHP में echo और print में क्या अंतर है?

Answer

Short Answer

Both echo and print are language constructs used to output data to the screen. The main differences are that echo can take multiple parameters and has no return value, making it marginally faster. print can only take a single argument and always returns 1, meaning it can be used in expressions.

Comparison Table

Feature echo print
Return Value None (void) Returns 1
Multiple Arguments Supported (e.g., echo "a", "b";) Not Supported
Speed Slightly faster Slightly slower
Usage in Expressions No Yes (e.g., $val = print("Hi");)

Code Example


// echo multiple strings
echo "Hello ", "World", "!"; 

// print returning a value (useful in ternary operators)
$isPrinted = print("Hello World!"); // Outputs: Hello World!
echo $isPrinted; // Outputs: 1

// echo inside an expression will cause a Syntax Error
// $val = (echo "test"); // ERROR!

Interview Tip

In modern PHP development, always use echo. The speed difference is microscopic, but echo is the universally accepted standard in the PHP community.

दोनों डेटा आउटपुट करते हैं, लेकिन छोटे अंतर हैं जो इंटरव्यूअर पूछते हैं।

फीचरechoprint
रिटर्न वैल्यूकोई नहीं (void)हमेशा 1
आर्गुमेंट्सकई, कॉमा-सेपरेटेडसिर्फ एक
स्पीडथोड़ी तेज़थोड़ी धीमी
एक्सप्रेशन मेंइस्तेमाल नहीं हो सकताहो सकता है
echo "Hello", " ", "World";\nprint "Hello World";

इंटरव्यू टिप: बताएं echo स्पीड और मल्टी-आर्ग सपोर्ट के लिए पसंदीदा है।

Was this answer clear?