How do I get specific key and its value from object?
Example I have output of my query:
"attribute_summary":"Color: Red",
"meta_data":[
{
"id":5858,
"key":"_number_field",
"value":"60,20"
},
{
"id":6275,
"key":"_mootmed",
"value":"278 x 138 x 80 mm"
},
{
"id":6276,
"key":"_kulu",
"value":"1m2 \/ 26tk"
},
{
"id":6277,
"key":"_varv_va",
"value":"hall"
},
{
"id":6278,
"key":"_alus_al",
"value":"8,6 m2 \/ 224 tk \/ 1350 kg"
},
{
"id":6279,
"key":"_alus_mo",
"value":"1200 x 1200 mm"
}
]
And I know if I query like this $product->attribute_summary;
I can get data Color: Red
But How do I get data of meta_data
? Like need to get key _alus_al
and its value displayed.
My Answer:
You can access the meta_data array and loop through it to find the specific key and its value. Here is an example code snippet:
php
foreach($product->meta_data as $data){
if($data->key == '_alus_al'){
echo $data->value;
}
}
This code will loop through the meta_data array and check if the key is equal to '_alus_al'. If it is, it will echo the corresponding value.
Rate this post
3 of 5 based on 5990 votesComments