1$neededObject = array_filter(
2 $arrayOfObjects,
3 function ($e) use (&$searchedValue) {
4 return $e->id == $searchedValue;
5 }
6);
1/**
2 * Find a value via object proprty name in a 2D array of objects.
3 * We often store encoded JS objects containing custom user data.
4 * This is an easy way to find specific details if you know the
5 * property name.
6 */
7$customOptions = [
8 {
9 userLabel: 'Check out my awesome label',
10 userName: 'Non-Stop Code Shop'
11 },
12 {
13 userColor: '#2680eb',
14 userFont: 'comic_sans'
15 }
16];
17
18function findObjectPropertyByName($propName, $arrayOfObjects)
19{
20 $array = array_filter($arrayOfObjects, function ($obj) use (&$propName) {
21 return array_key_exists('NotificationBody', get_object_vars($obj));
22 });
23
24 if (!empty($array)) {
25 return $array[0]->$propName;
26 }
27
28 return null;
29}
30
31$userFont = findObjectPropertyByName('userFont', $customOptions);