I have some legacy code and refactored an array to an ArrayObject. Now I have problems checking, if a variable is an array:
if (is_array($entity) && $otherCondition) {
// do something
}
The function is_array() returns false on an ArrayObject. See this report.
Simplest solution would be to use something like this:
function is_traversable($var) {
return is_array($var) || $var instanceof Traversable;
}
Is there some native way for PHP to do a check like this?
according to http://blog.stuartherbert.com/php/2010/07/19/should-is_array-accept-arrayobject/, you have to make the custom method you wrote in order to do what you wish...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With