I am trying to filter out empty entries in an object.
For example an object like this:
stdClass Object
(
[maten0] => stdClass Object
(
[XXS] =>
[XS] =>
[S] => 10
[M] => 10
[L] =>
[XL] =>
[XXL] =>
)
)
The desired output would be:
stdClass Object
(
[maten0] => stdClass Object
(
[S] => 10
[M] => 10
)
)
I create the object with json. Like so:
$kuubobject = json_decode($artikel['aantalkuub']);
I found out how to do this with arrays but the following does not work for objects:
$filteredobject = array_filter($kuubobject, 'strleng');
This gives me the error:
array_filter() expects parameter 1 to be array, object given
How can I do this with objects?
I've tried the following after the marked duplicate question:
$object = (object) array_filter((array) $kuubobject);
echo '<pre>';
print_r($object);
echo '</pre>';
But I get the same output as above.