Skip to content

Instantly share code, notes, and snippets.

View TheMadDeveloper's full-sized avatar

Keith Kerlan TheMadDeveloper

  • SF Bay Area, CA
View GitHub Profile
@TheMadDeveloper
TheMadDeveloper / iterate-list-example.php
Last active July 2, 2016 02:30
PHP sample iterating over an array or hash with efficient special processing on first and last element
<?php
# Iterates through the supplied hash or array with optional special processing on first and last element.
# PARAMETERS:
# $list: the hash or array to iterate over
# $fnMain: function($listElement) which should process the list elements
# $fnFirst: function($listElement) which should process the FIRST element in the list
# if null, no special processing is done, and the first element will be processed with $fnMain
# $fnLast: function($listElement) which should process the LAST element in the list
# if null, no special processing is done, and the last element will be processed with $fnMain
function iterateList($list, $fnMain, $fnFirst, $fnLast) {