php - in_array - 'in_object' equivalent? -
is there such function in_array
, can used on objects?
nope, can cast object array , pass in_array()
.
$obj = new stdclass; $obj->one = 1; var_dump(in_array(1, (array) $obj)); // bool(true)
that violates kinds of oop principles though. see comment on question , aron's answer.
Comments
Post a Comment