如何打印不在数组中的最多 10 个数字?

例如,我有一个数组,其中包含值 (2,3,4),但它可能为空。有什么办法可以打印出最多 10 个数字,但不能打印出数组中的数字,例如:(1, 5, 6, ... 10) ?我试过这个:但它变得混乱:


foreach ($locuri as $k) {

  for ($i=1; $i <= 10; $i++) {

    if ($k == $i) {

      continue;

    } else {

      echo $i;

    }

  }

}


BIG阳
浏览 103回答 2
2回答

慕桂英4014372

<?php$array = [2,3,4];//go through numbers from 1 to 10 and store it as $ifor ($i=0; $i <= 10; $i++) {&nbsp; &nbsp; //if $i is not in array echo it, the "!" changes the boolean value&nbsp; &nbsp; if ( !(in_array($i, $array)) ) {&nbsp; &nbsp; &nbsp; &nbsp; echo $i;&nbsp; &nbsp; }}?>如果您需要更多解释,请告诉我,因为代码看起来不言自明

大话西游666

它应该是:for ($i=1; $i <= 10; $i++) {&nbsp; foreach ($locuri as $k) {&nbsp; &nbsp; if ($k == $i) {&nbsp; &nbsp; &nbsp; $found = true;&nbsp; &nbsp; }&nbsp; }&nbsp; if($found == false) echo $i;&nbsp; $found=false;}
打开App,查看更多内容
随时随地看视频慕课网APP