I have a function like this:
// merge - merge two or more given trees and returns the resulting tree
function merge() {
if ($arguments = func_get_args()) {
$count = func_num_args();
// and here goes the tricky part... :P
}
}
I can check if all given arguments belong to the same type/class (class, in this case) using functions like get_class()
, is_*()
or even ctype_*()
but that operates (as far as I understand) at the single element level.
What I would ideally like to do is something similar to the in_array()
function but comparing the class of all elements in the array, so I would do something like in_class($class, $arguments, true)
.
I could do something like this:
$check = true;
foreach ($arguments as $argument) {
$check &= (get_class($argument) === "Helpers\\Structures\\Tree\\Root" ? true : false);
}
if ($check) {
// continue with the function execution
}
So my question is... is there a defined function for this? Or, at least, a better/more elegant method to accomplish this?