Created
July 7, 2023 10:39
-
-
Save michitheonlyone/81d93c40a7673469b0dd4206c985d772 to your computer and use it in GitHub Desktop.
The solution to find if a class exists in a array of classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
class A {} | |
class B {} | |
class C {} | |
$classes = [ | |
new A(), | |
new B(), | |
]; | |
var_dump( in_array(true, array_map(function ($c){ return $c instanceof A;}, $classes)) ); // returns true | |
var_dump( in_array(true, array_map(function ($c){ return $c instanceof C;}, $classes)) ); // returns false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment