倒序数字出现问题
P粉079091758
P粉079091758 2023-03-30 22:31:06
0
2
657

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

Antworte allen(1)
P粉079091758

已解决,

等号需要双个

  • Antwort 还有三个等号的 就是类型也要一样
    大瓶可乐@php.cn Autor 2023-04-01 21:37:14
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!