Can you provide an example of using in_array function in PHP to check for objects in an array?

When working with arrays in PHP, you may need to check if a specific object exists within the array. The in_array function can be used to accomplish this task by checking for the presence of a specific value within the array. To check for objects in an array, you can use the strict parameter of in_array to ensure that both the value and type of the object are matched.

// Example of using in_array function to check for objects in an array
$object1 = new stdClass();
$object2 = new stdClass();

$array = [$object1, $object2];

if (in_array($object1, $array, true)) {
    echo "Object1 is in the array";
} else {
    echo "Object1 is not in the array";
}