php search in object. array
$neededObject = array_filter(
$arrayOfObjects,
function ($e) use (&$searchedValue) {
return $e->id == $searchedValue;
}
);
php search in object. array
$neededObject = array_filter(
$arrayOfObjects,
function ($e) use (&$searchedValue) {
return $e->id == $searchedValue;
}
);
php find object by property name in array of objects
/**
* Find a value via object proprty name in a 2D array of objects.
* We often store encoded JS objects containing custom user data.
* This is an easy way to find specific details if you know the
* property name.
*/
$customOptions = [
{
userLabel: 'Check out my awesome label',
userName: 'Non-Stop Code Shop'
},
{
userColor: '#2680eb',
userFont: 'comic_sans'
}
];
function findObjectPropertyByName($propName, $arrayOfObjects)
{
$array = array_filter($arrayOfObjects, function ($obj) use (&$propName) {
return array_key_exists('NotificationBody', get_object_vars($obj));
});
if (!empty($array)) {
return $array[0]->$propName;
}
return null;
}
$userFont = findObjectPropertyByName('userFont', $customOptions);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us