Now that you have a grasp on how basic MySQL queries work, learning how to use the LIMIT & WHERE clauses are the next step. Unlike using a query that retrieves all the data, sometimes the user just needs to pull the first few rows, or be able to sort them as well. Using LIMIT & WHERE clauses in MySQL is a more efficient way of retrieving data.
When I first started heavily using arrays in PHP, often times the number of array values or items would need to be known, and this would be accomplished by using a foreach statement and counting up the number of iterations. Looking back, this was the most inefficient and long way possible to grab the total array items. Instead, the proper way to count the number of values or items in an array, is to use the built-in count() function. Here is a quick example to retrieve the number of items in a PHP Array:
<?php $array = array("dog", "cat", "tiger", "zebra"); $count = count($array); echo $count; //will print 4 ?>
There you have it! Simply use the count() function to retrieve the total number of items in a PHP Array.