PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

PHP · Theory

Echo

← All stacks

Theory

6/352

Echo

echo sends text to the page. echo 'Hello'; echo $name; You can echo several values: echo $a, $b; No return value. print is similar but returns 1 — almost nobody cares. Use echo.

<?= $name ?> is short echo inside HTML. Need short_open_tag / PHP 5.4+ echo short tag. Fine in modern PHP.

Trap — echo array — Array to string conversion. Use json_encode or a loop. Trap: missing quotes around strings.

Exam tip

echo 'Hello'; Don’t echo arrays.

Example

<?php
// Echo
$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";
}

Echo: scores array, print avg, then high marks. Say the output.

Short notes

  • Defecho prints to the response.
  • Ruleecho 'Hi'; or echo $name;
  • Trapecho an array.

Questions

1

echo vs print?

6 / 352

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.