I am working on to decode json data and get value from array. It is working fine if there is value in json array. But in some cases json is coming empty and i need to validate it. If json is empty then it will go in else condition.
$response = '[{"NUMBER":"","INV-NO":"","PL-NUM":"","TYPE":""},{"NUMBER":"","INV-NO":"","PL-NUM":"","TYPE":""}]';
$jsondata = json_decode($response,true);
if(!empty($jsondata))
{
echo "value in json data";
}else{
echo "no value";
}
2
Answers
Do something like this
You need to traverse each sub-child of array and get the count of not-empty values. Then you can apply check based on that
Output: https://3v4l.org/WMtas