<?php
$a = '{"product": [{
"id" : "001",
"title":"Product One",
"price":"Price One",
"desc":"Description One",
"image": [{
"img":"image 1 1"
},{
"img":"image 1 2"
},{
"img":"image 1 3"
}]
}, {
"id" : "002",
"title":"Product Two",
"price":"Price Two",
"desc":"Description Two",
"image": [{
"img":"image 2 1"
},{
"img":"image 2 2"
},{
"img":"image 2 3"
}]
}]
}';
$product = json_decode($a, true);
function getArrValue($key, &$product) {
foreach ($product["product"] as $product) {
if (!empty($product["id"])) {
return $product;
}
}
}
var_dump(getArrValue("002", $product));