Problem with numbers in reverse order
P粉079091758
P粉079091758 2023-03-30 22:31:06
0
2
732

Use if, elseif and else statements to modify the output slightly:

When the loop variable $i is 10 and until its value is down to 3, it should simply print the loop variable followed by a newline.

When the loop variable is 2, it should print "Ready!", followed by a newline.

When the loop variable is 1, it should print "Set!", followed by a newline.

When the loop variable is 0, it should print "Go!".


<?php

  for($i = 10; $i >= 0; $i--){

    $j = $i;

    if($j > 2){

      echo $j."\n";

    }elseif($j = 2){

      echo "Ready!\n";

    }elseif($j = 1){

      echo "Set!\n";

    }else{

      echo "Go!";

    }

  }

?>



输出结果为:10 9 8 7 6 5 4 3 Ready! Ready! Ready!


为什么会卡在2那里,求解原理。

P粉079091758
P粉079091758

reply all(1)
P粉079091758

Solved,

The equal sign requires double

  • reply There are also three equal signs, even the types must be the same.
    大瓶可乐@php.cn author 2023-04-01 21:37:14
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!