Home  >  Q&A  >  body text

Ask an idiot question

The random function rand() generates ten random integers between (-10,10) and saves them in the arr1 array. Query whether there is a random integer 0 among the ten random integers generated in array arr1. If yes, output "the ten random integers generated this time contain the random number 0" in the web page; if not, output in the web page "the ten random integers generated this time do not contain the random number 0".

 蒹葭苍苍 蒹葭苍苍2616 days ago946

reply all(1)I'll reply

  • super|鹏

    super|鹏2017-09-13 16:30:26

    <?php

    $arr = array();

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

    $arr[$i] = rand(-10,10);

    }

    echo "<pre>";

    var_dump($arr);

    foreach ($arr as $k => $v) {

    if($v == 0){

    echo 'The ten random integers generated this time contain the random number 0';

    die;

    }

    }

    echo 'The ten random integers generated this time do not contain the random number 0';


    reply
    1
  • Cancelreply