Skip to content

Instantly share code, notes, and snippets.

@mikedfunk
Created November 16, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikedfunk/8e0733610d4a4fa8bc53 to your computer and use it in GitHub Desktop.
Save mikedfunk/8e0733610d4a4fa8bc53 to your computer and use it in GitHub Desktop.
optionally allow an array in php
<?php
// ...
public function processData($input)
{
if (is_array($input)) {
// if it's an array, loop through each one and recursively
// call the function we're in but this time without an
// array. So it should skip past this line for each one.
return array_map([$this, 'processData'], $input);
}
// process an individual item here since it is not an array...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment