Is there such a function like in_array
, but can be used on objects?
Nope, but you can cast the object to an array and pass it into in_array()
.
$obj = new stdClass; $obj->one = 1; var_dump(in_array(1, (array) $obj)); // bool(true)
That violates all kinds of OOP principles though. See my comment on your question and Aron's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With