Source Code:
(back to article)
<?php $array = [new stdClass(), new stdClass(), new stdClass()]; $objectToRemove = new stdClass(); $array = array_filter($array, function ($obj) use ($objectToRemove) { return $obj !== $objectToRemove; }); if (count($array) < count($array) - 1) { echo "Object removed from the array!"; } else { echo "Object not found in the array."; } ?>
Result:
Report an issue