Difference between Echo and Print — PHP Technical Interview Questions & Answers

Difference between Echo and Print

Difference between Echo and Print

  • echo can take multiple arguments: echo $a, $b; print cannot. print returns 1; echo is a language construct with no return. Speed difference is not a viva that matters. Say: we use echo.
  • Trap: a two-page table with no example.

Technical Interview Tip: echo for daily work. print = one arg + return 1.

Code Examples for Difference between Echo and Print

Difference between Echo and Print — working example

<?php
// Difference between Echo and Print
$scores = [80, 90, 70];
$avg = array_sum($scores) / count($scores);
echo "avg=" . number_format($avg, 1) . "\n";
foreach ($scores as $s) {
  if ($s >= 80) echo "high: $s\n";
}

Difference between Echo and Print: scores array, print avg, then high marks. Say the output.

How to Explain Difference between Echo and Print to an Interviewer

Main difference?

echo can output several values print returns 1