As for for PHP >= 7.1 it is possible to detect if a variable is iterable or not using is_iterable()
.
is there an alternative to this for PHP <= 7 ?
how can i perform this since im working on php 7.0 ?
You just have to test, if the given var is of type Traversable
or if it is an array. Everything else isn't iterable.
if (!function_exists('is_iterable')) {
function is_iterable($var)
{
return is_array($var) || $var instanceof \Traversable;
}
}
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