This question already has an answer here:
I have the follow array and and am trying to get the meta_value for the the object that has the meta_key of license_number. How can I return that value?
items: [
{
account_id: "7890",
t: 1990007,
meta_value: "27",
id: "123",
create_date: 1507174015113,
update_date: 1512628710384,
meta_key: "content_items",
},
{
account_id: "7890",
t: 1990007,
meta_value: "123456",
id: "123",
create_date: 1498492590855,
update_date: 1498492590855,
meta_key: "location_id",
},
{
account_id: "7890",
t: 1990007,
meta_value: "123456789",
id: "123",
create_date: 1498492590855,
update_date: 1498492590855,
meta_key: "license_number",
}
]
</div>
Use array_filter() and a callable to fit your needs (here an anonymous fonction) :
$searchedValue = 'license_number';
$o = array_filter( $items,
function ($e) use (&$searchedValue) {
return $e->meta_key == $searchedValue;
}
);
Note the return is an array of objects containing all values that fit the condition. This will give you the first result.
reset($o);