3v4l.org

run code in 300+ PHP versions simultaneously
<?php $x = [ 123 => ['name' => 'xxx'], 456 => ['name' => 'yyy'], ]; echo \array_key_exists(123, $x) ? 'yes' : 'no'; echo "\n"; $x = [ ['id' => 123, 'name' => 'xxx'], ['id' => 456, 'name' => 'yyy'], ]; $check = 123; $y = \array_filter($x, function ($value) use ($check) { return $value['id'] === $check; }); echo \count($y) ? 'yes' : 'no'; // if array child id === 123 in any of the children, // then echo yes, // (without using a loop, and by using an array function)
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
yes yes

preferences:
74.86 ms | 402 KiB | 60 Q