3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_cyclic(&$array) { $isRecursive = false; set_error_handler(function ($errno, $errstr) use (&$isRecursive) { $isRecursive = $errno === E_WARNING && mb_stripos($errstr, 'recursion'); }); try { count($array, COUNT_RECURSIVE); } finally { restore_error_handler(); } return $isRecursive; } $array = [1, [2, 3]]; $array[1][1] = &$array; var_dump(is_cyclic($array));

preferences:
25.51 ms | 408 KiB | 5 Q