yoklainterview sim

Backend Php Stdlib Http Interview Questions

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

Try the real simulation →

Sample questions

Php Stdlib HttpDifficulty 2
$prices = ['apple' => 2, 'pear' => 3];
$doubled = array_map(fn($p) => $p * 2, $prices);
print_r($doubled);

What is printed?
  • aArray ( [0] => 4 [1] => 6 ) — array_map always renumbers keys starting from 0
  • bArray ( [apple] => 2 [pear] => 3 ) — the closure is ignored because array_map cannot take arrow functions
  • cArray ( [apple] => 4 [pear] => 6 ) — original keys are preserved, each value doubled
  • dA fatal error, because array_map cannot be combined with a single input array
Explanation:array_map() preserves the original array's keys whenever exactly one input array is passed — only when multiple arrays are passed does it reindex the result numerically. Here each value is doubled (22=4, 32=6) while the string keys 'apple' and 'pear' stay attached to their new values.
Php Stdlib HttpDifficulty 2
$a = [1, 2, 3];
$b = [10, 20, 30];
$result = array_map(null, $a, $b);
print_r($result[1]);

What is printed?
  • aArray ( [0] => 2 [1] => 20 )
  • b22 — array_map(null, ...) sums corresponding elements when the callback is null
  • c2 — only the first array's element at that position is kept
  • dArray ( [0] => 1 [1] => 10 [2] => 2 [3] => 20 ) — all elements flattened into one array
Explanation:Passing null as the callback with multiple arrays makes array_map() zip them: each output element is an array containing the corresponding element from every input array at that index. $result[1] pairs $a[1]=2 with $b[1]=20, giving [2, 20]. The result is reindexed numerically regardless of the input arrays' original keys.
Php Stdlib HttpDifficulty 2
A junior developer filters a mixed array to drop "empty-ish" values before saving to the database:
$values = [0 => 'x', 1 => 0, 2 => '', 3 => 'y', 4 => null, 5 => '0'];
$filtered = array_filter($values);
print_r($filtered);

What gets printed?
  • aArray ( [0] => 'x' [1] => 0 [2] => '' [3] => 'y' [4] => null [5] => '0' ) — array_filter() without a callback returns the array unchanged
  • bArray ( [0] => 'x' [1] => 'y' ) — surviving values are renumbered starting from 0
  • cArray ( ) — array_filter() without an explicit callback always returns an empty array
  • dArray ( [0] => x [3] => y ) — falsy values (0, '', null, '0') are dropped and the original keys of survivors are kept
Explanation:Without a callback, array_filter() uses a boolean cast on each value: 0, '', null, and the special string '0' are all falsy in PHP and get removed, while 'x' and 'y' are truthy and survive. Crucially, array_filter() never renumbers keys — the surviving elements keep their original array keys (0 and 3 here), which is why a subsequent foreach or array_values() call is often needed if a clean 0-based list is required.
Php Stdlib HttpDifficulty 2
An array holds a key whose value is explicitly set to null: $data = ['name' => 'Ada', 'age' => null];. What is the key difference between isset($data['age']) and array_key_exists('age', $data) in this case?
  • aThere is no difference — both return true whenever the key is present, whether or not its value is null
  • bisset() returns false because it also requires the value to be non-null, whereas array_key_exists() returns true because it only checks whether the key is present in the array
  • carray_key_exists() returns false for a null value while isset() returns true, since isset() only checks key presence and ignores the value entirely
  • dBoth return false, because PHP treats a key whose value is null as if the key were never set in the array
Explanation:isset() checks two things at once: that the key exists AND that its value is not null — so for a key explicitly holding null, isset() returns false. array_key_exists() checks only whether the key is present in the array, regardless of what value (including null) is stored there, so it returns true. This distinction matters whenever a config or optional field can legitimately hold null and code needs to tell "missing" apart from "present but null".
Php Stdlib HttpDifficulty 1
$total = array_reduce([1, 2, 3, 4], fn($carry, $n) => $carry + $n, 0);
echo $total;

What is printed?
  • a10
  • b0
  • c4
  • d24
Explanation:array_reduce() walks the array left to right, calling the callback with the running $carry (starting at the initial value 0) and each element $n, replacing $carry with the callback's return value each time: 0+1=1, 1+2=3, 3+3=6, 6+4=10. The final carry, 10, is returned.
Php Stdlib HttpDifficulty 3
$result = array_reduce([], fn($carry, $n) => $carry + $n);
var_dump($result);

What is printed?
  • aint(0)
  • bbool(false)
  • cNULL
  • dIt throws a fatal error because array_reduce() requires an explicit initial value
Explanation:array_reduce()'s third parameter (the initial carry) defaults to null when omitted. Since the input array is empty, the callback is never invoked at all, and the function simply returns the initial value unchanged — null here, not 0. This is a common source of bugs when someone assumes an omitted initial value behaves like 0 for a numeric sum.

Test yourself against the 3300-question Backend bank.

Start interview