Created
July 19, 2011 11:05
-
-
Save makasim/1091991 to your computer and use it in GitHub Desktop.
array_filter usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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