I have this array, i am trying to get the "id" when sku matches to 'Testproduct_2327'.
I am not sure how to implement this.
$main_array = array (
'status' => true,
'response' =>
array (
'code' => 200,
'result' =>
array (
'products' =>
array (
0 =>
array (
'id' => '0242e39e-bf20-11eb-fc6f-4cc6b4b8af34',
'sku' => 'Testproduct_0'
),
1 =>
array (
'id' => '0242e39e-bf20-11eb-fc6f-4cc6b6682978',
'handle' => 'vend_2327handle',
'sku' => 'Testproduct_1'
),
2 =>
array (
'id' => '0242e39e-bf20-11eb-fc6f-4cc6d31d1d02',
'handle' => 'vend_2327handle',
'sku' => 'Testproduct_2327',
),
),
),
)
);
I have tried this & it not working
array_walk_recursive($main_array, function ($item, $key) {
if($key == "sku" && $item == "Testproduct_2327"){
echo $item;
}
});
Any thoughts on this ? php compiler - https://rextester.com/AKIXIC51695
Thanks