Middle+
What is the output of the following code? <?php $g = range(5,8); $h = array("a", "b", "c", "e"); for($i = 0; $i < count($g); $i++) { foreach ($h as $j) { echo $i.$j; break; } }
sobes.tech AI
Answer from AI
Code:
<?php
$g = range(5,8); // array [5,6,7,8]
$h = array("a", "b", "c", "e");
for($i = 0; $i < count($g); $i++) {
foreach ($h as $j) {
echo $i.$j;
break;
}
}
Explanation:
- Outer loop over $i from 0 to 3 (4 iterations)
- Inner foreach loop over array $h, but immediately
break, so only the first iteration of the inner loop runs for each $i - During each iteration, output is the concatenation of $i and $j, where $j is the first element of array $h, i.e., "a"
Final output:
0a1a2a3a
That is, for each $i, the output is "i" + "a" with no spaces.