3
In PHP, to check if a array
is empty we can use the function (or language constructor) empty
.
Thus:
$a = array();
$b = array(1, 2);
var_dump(empty($a), empty($b)); // Imprime: bool(true), bool(false)
But the same does not happen with stdClass
.
$a = (object) array();
$b = (object)array('nome' => 'wallace');
$c = new stdClass(); // A mesma coisa que $a
var_dump(empty($a), empty($b), empty($c)); // Imprime: bool(false), bool(false), bool(false)
See on IDEONE
So what’s the way to know that an object stdClass
is empty or not in PHP?
James, I think you’re new to stackoverlow. You should use the comments for this sort of thing. This is usually a flashy for negative votes, but to help you, I will edit your answers, to you how it could improve, okay?
– Wallace Maxters
This should be posted in the comments. When you will present a hypothesis, you use the comments. When you will present a concrete solution, you use the answer.
– Wallace Maxters
Don’t be in a hurry to answer, just hurry up and help.
– Edilson
I guess we can remove that comment jug from here
– Wallace Maxters
@Wallacemaxters just so I know, you would remove all comments in this case? I was wondering if I was asking for approval to do it, or if each one has to delete his comment to clear, thanks!
– Thyago ThySofT
It is that the subject has escaped the context of the question. This is not recommended
– Wallace Maxters