Skip to content

Instantly share code, notes, and snippets.

@makasim
Created July 19, 2011 11:05
Show Gist options
  • Save makasim/1091991 to your computer and use it in GitHub Desktop.
Save makasim/1091991 to your computer and use it in GitHub Desktop.
array_filter usage
<?php
class AdWizard
{
protected $steps = array();
// ...
/**
* How to find a step with an identifier provided using array_filter function
*/
public function step($identifier)
{
list($step) = \array_filter($this->steps, function($step) use ($identifier) {
return $step->getIdentifier() == $identifier;
});
if (false == $step)) {
throw new \InvalidArgumentException('The step with identifier `'.$identifier.'` was not found');
}
return $step;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment