3v4l.org

run code in 300+ PHP versions simultaneously
<?php $before = [ ['type' => 'foo'], ['type' => 'only-first-of-this'], ['type' => 'bar'], ['type' => 'only-first-of-this'], ['type' => 'baz'], ]; $found = 0; $after = array_filter( $before, static fn ($item) => $item['type'] !== 'only-first-of-this' || $found++ === 0, ); var_dump($before, $after); $found = 0; $after2 = array_filter( $before, static function ($item) use (&$found) { return $item['type'] !== 'only-first-of-this' || $found++ === 0; }, ); var_dump($after2);

preferences:
24.29 ms | 405 KiB | 5 Q