title: PHP Count Arrays from MySQL counts Incorrectly
body: <p>I am having trouble correctly counting elements within the array that I pulled from my database. Please see my code below:</p>
  
  <pre><code>// Create connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
  
  // Check connection
  if (!$conn) 
  {
      die("Connection failed: " . mysqli_connect_error());
  }
  echo "Connected successfully!"; 
  
  //NEW QUERY TO OUR DATABASE
  $query = $conn -&gt; query("Select distinct Race from Races");
  while($race[] = $query-&gt;fetch_object());
  
  //Check how many elements are within our query
  $racecount = count($race);
  echo "&lt;br&gt;" . $racecount . "&lt;br&gt;&lt;br&gt;";
  $racecount = count($race,COUNT_RECURSIVE);
  echo "&lt;br&gt;" . $racecount . "&lt;br&gt;&lt;br&gt;";
  
  var_dump($race);
  
  echo "&lt;br&gt;&lt;br&gt;&lt;br&gt;";
  </code></pre>
  
  <p>Using both type count() in both ways yields the same result of "4". However, please see the result from my var_dump.</p>
  
  <pre><code>array(4) { [0]=&gt; object(stdClass)#3 (1) { ["Race"]=&gt; string(5) "Human" } [1]=&gt; object(stdClass)#4 (1) { ["Race"]=&gt; string(7) "Vampire" } [2]=&gt; object(stdClass)#5 (1) { ["Race"]=&gt; string(5) "Demon" } [3]=&gt; NULL } 
  </code></pre>
  
  <p>Var_dump shows that it is an array with 4 elements within it. So count was correct, it's just not giving me the number that I'm looking for. </p>
  
  <p>Thus, I have three questions.</p>
  
  <p>1) How do I count my elements correctly?</p>
  
  <p>2) Could someone explain to me why this reads as 4 elements?</p>
  
  <p>3) Is my array not multi-dimensional? (since both counts yield the same result of 4)</p>
  
  <p>Best Regards and Thanks in advance,</p>
  
  <p>Josh</p>