title: generate Unique ID sequence
body: <p>I want to generate a 7 number Unique ID this is my function to generate.</p>
  
  <pre><code>function generate_guid($length){
      $alphabet = '1234567890';
      $tip = array();
      $alphaLength = strlen($alphabet) - 1;
      for ($i = 0; $i &lt; $length; $i ++) {
          $n = rand(0, $alphaLength);
          $tip[] = $alphabet[$n];
      }
      return implode($tip);
  }
  </code></pre>
  
  <p>Now this is my register function</p>
  
  <pre><code>function create_user($email, $name, $country, $password){
  
      $ipaddress = $_SERVER['REMOTE_ADDR'];    
  
      $guid = generate_guid(7);
  
      $active = 0;
  
      if (email_exists($email)) {
          return false;
      } else 
          if (name_exists($name)) {
              return false;
          } else {
  
              $hashed_password = password_hash($password, PASSWORD_BCRYPT);
  
              $db = dbconnect();
  
              //MyQuery Code//
  
              $stmt-&gt;close();            
  
              return true;
          }
  }
  </code></pre>
  
  <p>Now I am able to generate and I am able to check if user name and email exist. my issue is how can I check if the guid exist without error and generate new to insert into db ? Or if some one has a better suggestion. the main thing I am trying to accomplish is must be 7 no more lengths long all numbers.</p>
  
  <p>I read about unique ID but it says its not guaranteed, also it has letters. is there a better approach? </p>
  
  <p>I came across this but is aspx <a href="https://stackoverflow.com/questions/5361137/how-to-generate-unique-id-per-user">how to generate unique id per user?</a> would it be possible to generate my function in sequence?</p>