3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['type' => 'foo'], ]; function hasDependencyTypeLoop(array $dependencies, string $type): bool { foreach ($dependencies as ['type' => $currentType]) { if ($currentType === $type) { return true; } } return false; } function hasDependencyTypeArrayAny(array $dependencies, string $type): bool { return array_any($dependencies, fn() => $currentType === $type); } var_dump(hasDependencyTypeLoop($data, 'foo')); var_dump(hasDependencyTypeArrayAny($data, 'foo'));
Output for 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
bool(true) Warning: Undefined variable $currentType in /in/a7int on line 18 bool(false)
Output for 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30
bool(true) Fatal error: Uncaught Error: Call to undefined function array_any() in /in/a7int:18 Stack trace: #0 /in/a7int(22): hasDependencyTypeArrayAny(Array, 'foo') #1 {main} thrown in /in/a7int on line 18
Process exited with code 255.

preferences:
59.22 ms | 849 KiB | 4 Q