How about this:
function convert($array) { return (count($array) === 0) ? "" : $array; } $empty_array = array(); $empty_array = convert($empty_array);
This just converts it to an empty string if the array is empty.
The object is a bit more complicated, but you can just use get_object_vars () :
function convert($object) { return (count(get_object_vars($object)) === 0) ? "" : $object; }
Nb .: You cannot check an object for private variables.
Sitse source share