Created
January 4, 2016 15:12
-
-
Save przor3n/0268724892b81bac1cbd to your computer and use it in GitHub Desktop.
yield and iterator_to_array as a dynamic generator
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
private function getSearchTypeList() | |
{ | |
foreach ($this->choices as $choice) { | |
yield $choice => 'type.' . $choice; | |
} | |
} | |
//then | |
iterator_to_array($this->getSearchTypeList()) | |
//returns: | |
// [ 'a' => 'type.a', 'b' => 'type.b' ... ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment