What is the difference between echo and print in PHP?
Why Interviewers Ask This
This is a classic screening question for PHP roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
Both echo and print are used to output data in PHP, but they have key differences. echo is a language construct (not strictly a function), can accept multiple comma-separated arguments (echo "Hello", " World";), and has no return value — it is marginally faster. print also a language construct, always returns 1, making it usable in expressions: $x = print("Hello");. It accepts only one argument. In practice, echo is used far more commonly. Neither requires parentheses for a single argument, though you can use them for clarity.
Common Mistake
Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your PHP experience.