yoklainterview sim

Backend Php Memory Performance Interview Questions

75 verified Backend Php Memory Performance interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Php Memory PerformanceDifficulty 1
$a = [1, 2, 3];
$b = $a;
$b[] = 4;
echo count($a);

What does this code print?
  • a3
  • b4
  • c7
  • dNotice: array modified after copy
Explanation:PHP arrays are value types copied on assignment: $b becomes an independent copy of $a. Appending 4 to $b does not change $a, so count($a) stays 3. No notice or error is raised for this.
Php Memory PerformanceDifficulty 1
$a = 10;
$b = &$a;
$a = 20;
echo $b;

What does this code print?
  • a10
  • b0
  • c20
  • dUndefined variable warning, then blank output
Explanation:$b = &$a makes $b an alias for the same variable slot as $a, a true reference rather than a copy. Changing $a to 20 changes the value both names refer to, so $b also reads as 20.
Php Memory PerformanceDifficulty 1
$fruits = ['a' => 'apple', 'b' => 'banana', 'c' => 'cherry'];
unset($fruits['b']);
echo count($fruits);

What does this code print?
  • a1
  • b2
  • c3
  • dFatal error: undefined key 'b'
Explanation:unset() on an array element removes just that one key/value pair. The other two entries remain untouched, and no error is raised for removing an existing key.
Php Memory PerformanceDifficulty 1
$x = 5;
unset($x);
var_dump(isset($x));

What does this code print?
  • aint(5)
  • bNULL
  • cbool(true)
  • dbool(false)
Explanation:unset() destroys the variable binding entirely. isset($x) checks whether a variable exists and is not null, so after unset it reports false, and var_dump of that boolean prints bool(false).
Php Memory PerformanceDifficulty 1
function addItem($arr) {
    $arr[] = 99;
    return count($arr);
}
$list = [1, 2, 3];
$result = addItem($list);
echo count($list) . ' ' . $result;

What does this code print?
  • a3 3
  • b4 4
  • c4 3
  • d3 4
Explanation:Without an & in the parameter, $arr is a value copy of $list inside the function. Appending to it only grows the local copy, so addItem returns 4, while the caller's $list is untouched and still has 3 elements.
Php Memory PerformanceDifficulty 1
$nums = [1, 2, 3];
foreach ($nums as $n) {
    $n = $n * 10;
}
print_r($nums);

What does this code print?
  • a[10, 20, 30]
  • b[1, 2, 3]
  • c[1, 2, 30]
  • dFatal error
Explanation:Without &, $n is a copy of each element for that iteration only. Reassigning $n inside the loop body has no effect on the original array, so $nums prints unchanged.

Test yourself against the 3300-question Backend bank.

Start interview