Return to the beginning of the results of a for loop

You can instantly access any position in an array by specifying the index.

i.e. to get the first element of the $search_results array:

$first_result = $search_results[0];

Note if you’re not used to working with arrays, they are “0” indexed in most languages, which means the first element’s index is 0, the second is 1, etc.

This is what your loop is basically doing as well. Each time it accesses a different number directly, $search_results[$i] is just putting the value of $i in the same spot as I had the 0 above.

You can also change the value of $i in your loop if you want to start the loop over, for instance. Adding the line:

$i = 0;

…would send you back to the beginning. However I would not recommend you work with the index of a loop until you are quite comfortable with them.