Print — PHP Technical Interview Questions & Answers
- print 'Hello'; also writes to the page. It always returns 1 so it can sit in an expression. Teams still write echo. Know both for MCQs.
- Trap: treating print as a function with two arguments like echo $a, $b — print takes one argument.
Technical Interview Tip: print 'Hello'; — one argument. echo is more common.
Code Examples for Print
Print — working example
<?php
// 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";
}Print: scores array, print avg, then high marks. Say the output.
How to Explain Print to an Interviewer
Can print take two strings like echo?
No One argument