Last active
March 8, 2017 14:57
-
-
Save Digi92/4a4d2376e127ab52551debadc83e52c6 to your computer and use it in GitHub Desktop.
Find entry by object property from a array of objects
This file contains hidden or 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 | |
| // Note: This will return all results with if true | |
| $neededObject = array_filter( | |
| $arrayOfObjects, | |
| function ($element) use (&$searchedValue) { | |
| /**@var element $element*/ | |
| return $element->id == $searchedValue; | |
| } | |
| ); | |
This file contains hidden or 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 | |
| // Note: This will return only the first hit | |
| $item = null; | |
| foreach ($array as $struct) { | |
| /**@var element $element*/ | |
| if ($element == $struct->ID) { | |
| $item = $struct; | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment