I am finding the value either exists in object array in php.
I would’t like to traverse whole the object array, Is their any alternative in php for object just like is_array()?
Edited:
if I var_dump($te_ws) then it shows this output . . .
array(2) { [0]=> object(stdClass)#22 (3) { ["id"]=> string(2) "12" ["fk_webapp_id"]=> string(1) "3" ["fk_tenant_id"]=> string(2) "12" } [1]=> object(stdClass)#25 (3) { ["id"]=> string(2) "13" ["fk_webapp_id"]=> string(1) "5" ["fk_tenant_id"]=> string(2) "12" } }
$is_checked = FALSE;
if (!empty($te_ws)) {
foreach ($te_ws as t) {
if ($t->id === 4) {
$is_checked = TRUE;
}
}
}
Is it possible to check the value 4 from array of object either exists using php built in function?
What you are asking for seems very strange. What are you doing that you need to test for membership of a value in an object?
In simple cases you can just cast an object to an array:
However this breaks down for any non-trivial object:
The following function will get a little closer to what you describe. But it won’t find properties computed with Magic Methods.