Variable Arguments — PHP Technical Interview Questions & Answers

Variable Arguments

Variable Arguments

  • Variable Arguments is a PHP topic. In plain words you use it for $marks = 72 in a result script. Don’t start with a slogan — start with that picture.
  • Smallest example: $name = 'Asha';. Type it, run it, and say what you see. If you can do that from memory, you know Variable Arguments.
  • From the example next to this theory: Variable Arguments: scores array, print avg, then high marks.
  • Trap: using marks without $. Fix that before you talk about advanced PHP.
  • Viva: what is Variable Arguments? Then show $name = 'Asha';. Then name the trap.

Technical Interview Tip: What is Variable Arguments? Show this: $name = 'Asha';. Trap: using marks without $.

Code Examples for Variable Arguments

Variable Arguments — working example

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

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

How to Explain Variable Arguments to an Interviewer

What is Variable Arguments?

Used for $marks = 72 a result script Not just the heading

Give one small example of Variable Arguments.

$name = 'Asha'; Variable Arguments: scores array, print avg, then high marks

What mistake do beginners make with Variable Arguments?

using marks without $ Show the fix

Where do you use Variable Arguments?

a result script $marks = 72