title: I want to check values are present in the array and print one random value, but it is giving undefined index error
body: <p>I want to check values are present in the array and print one random value, but it is giving undefined index error</p>
  <p>Here is the code</p>
  <pre><code>&lt;?php
  
  $agents = array(9986344xxx,9663275yyy);
  function agent(){
      global $agents;
      if (in_array(9986344xxx,$agents) || in_array(9663275yyy, $agents)) {
          $random = array_rand($agents);
          echo $agents[$random[0]];
       } 
       else{
          echo &quot;notfound&quot;;
       }
  }
  
  agent();
  </code></pre>