Output is: 1 2 3 4 5 6 7

, 2.

Output is: 1 7 2

, 3.

Output is: 1 3 5 7

, 4.

Compilation error.

">
MCQs > IT & Programming > PHP 5 >

What will be the output of the following PHP 7.1 code snippet?

<?php

function xrange($first, $last, $forward = 1)

{ if ($first < $last) {

if ($forward <= 0) {

throw new LogicException('The value of forward should be positive');

}

for ($i = $first; $i <= $last; $i += $forward){

yield $i;

}

} else {

if ($forward >= 0) {

throw new LogicException('The value of forward should be negative');

}

for ($i = $first; $i >= $last; $i += $forward){

yield $i;

}

}

}

echo "\n";

echo 'Output is: ';

foreach (xrange(1, 7, 2) as $num) {

echo "$num";

}

?>


PHP 5 MCQs

What will be the output of the following PHP 7.1 code snippet?

<?php

function xrange($first, $last, $forward = 1)

{ if ($first < $last) {

if ($forward <= 0) {

throw new LogicException('The value of forward should be positive');

}

for ($i = $first; $i <= $last; $i += $forward){

yield $i;

}

} else {

if ($forward >= 0) {

throw new LogicException('The value of forward should be negative');

}

for ($i = $first; $i >= $last; $i += $forward){

yield $i;

}

}

}

echo "\n";

echo 'Output is: ';

foreach (xrange(1, 7, 2) as $num) {

echo "$num";

}

?>


Answer

Correct Answer:

Output is: 1 3 5 7

Explanation:

Note: This Question is unanswered, help us to find answer for this one

PHP 5 Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

PHP 5 Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it