Simple PHP increment function

Whenever I have to output a numbered list of data I usually run the following code to achieve the required result.

$counter = 0;
// for loop that does all the required code
$counter++;
// end for

but I have discovered a lovely little function that does all this for me.

function increment(&$counter){
  $counter++;
  return $counter
}

now I simply call

increment($whichever_counter)

and it automatically outputs the next numeric.

Great! Simple and easy to use…..that’s the way to code.


Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.