title: How do I scan an array and stop the scan when the number becomes false, and echo what number made the loop false in PHP
body: <p>Basically I am creating a simple music player in PHP and I am setting the id of each song that is played in an array. I have a script which pulls a random number and plays the song with the corresponding id. I want to make it so that if the song has already played that it wont play again.</p>
  
  <p>Currently I have it generate a random number, and if that number has already been played then it adds 1 to the random number.</p>
  
  <p>The problem is if the number that is the result of adding 1 to the random number, it will then play that song again. I was attempting to store the songs played in an array and just increment the number until it doesn't exist in the array but I am struggling to find a solution to the problem.</p>
  
  <p>My code is as follows: </p>
  
  <pre><code>&lt;?php
  session_start();
  $con=mysqli_connect("blah blah blah");
  
  // Check connection
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  if (!isset($_SESSION['played'])) {
      $_SESSION['played'] = array();
  }
  
  $result = mysqli_query($con,"SELECT * FROM Data") ;
  $num_rows = mysqli_num_rows($result);
  $numsongs= .20 * $num_rows;
  $numsongs=floor($numsongs);
  
  $music = rand(1,$numsongs);
  if (in_array($music, $_SESSION['played'])) {$music = $music+1;};
  
  /* goes on to play music below */
  
  $_SESSION['played'][] = $music;
  ?&gt;
  </code></pre>
  
  <p>I didn't put my whole script in, the script works minus the repeating of songs. I only included a snippet of how I wrote the repeating script to give an idea of how I attempted it. </p>
  
  <p>Thanks in advance! </p>