- json_decode: documentation ( source)
- array_filter: documentation ( source)
<?php
$json = '[
{
"CarID": "f11gh126-dee8-46ef-9665-69119c354575",
"CarReg": "ABCD"
},
{
"CarID": "e258f6d4-4503-5d7e-b25c-1fb9767061e2",
"CarReg": "DEFG"
}
]';
$arr = json_decode($json, true);
$carId = array_filter($arr, function($item){
return $item['CarReg'] == 'ABCD';
})[0]['CarID'];
echo $carId;