3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array( 'name' => 'Supplier A', 'productName' => 'ABC', ), array( 'name' => 'Supplier B', 'productName' => 'ABC', ), array( 'name' => 'Supplier B', 'productName' => 'DEF', ), array( 'name' => 'Supplier C', 'productName' => 'XYZ', ), array( 'name' => 'Supplier D', 'productName' => 'BBB', ), array( 'name' => 'Supplier E', 'productName' => 'ABCDEF', ), array( 'name' => 'Supplier F', 'productName' => 'ABCDEF', ), ); $result = array_filter( $data, function($value) use ($data) { return count(array_filter( $data, function ($match) use ($value) { return $match == $value; } ) > 1); } ); var_dump($result);
Output for 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, true given in /in/o4qmE:42 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/o4qmE(34): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/o4qmE on line 42
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, true given in /in/o4qmE:42 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/o4qmE(34): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/o4qmE on line 42
Process exited with code 255.
Output for 8.2.0 - 8.2.18
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /in/o4qmE:42 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/o4qmE(34): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/o4qmE on line 42
Process exited with code 255.
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /in/o4qmE:42 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/o4qmE(43): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/o4qmE on line 42
Process exited with code 255.
Output for 8.0.0 - 8.0.9
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in /in/o4qmE:42 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/o4qmE(43): array_filter(Array, Object(Closure)) #2 {main} thrown in /in/o4qmE on line 42
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/o4qmE on line 42 array(7) { [0]=> array(2) { ["name"]=> string(10) "Supplier A" ["productName"]=> string(3) "ABC" } [1]=> array(2) { ["name"]=> string(10) "Supplier B" ["productName"]=> string(3) "ABC" } [2]=> array(2) { ["name"]=> string(10) "Supplier B" ["productName"]=> string(3) "DEF" } [3]=> array(2) { ["name"]=> string(10) "Supplier C" ["productName"]=> string(3) "XYZ" } [4]=> array(2) { ["name"]=> string(10) "Supplier D" ["productName"]=> string(3) "BBB" } [5]=> array(2) { ["name"]=> string(10) "Supplier E" ["productName"]=> string(6) "ABCDEF" } [6]=> array(2) { ["name"]=> string(10) "Supplier F" ["productName"]=> string(6) "ABCDEF" } }
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
array(7) { [0]=> array(2) { ["name"]=> string(10) "Supplier A" ["productName"]=> string(3) "ABC" } [1]=> array(2) { ["name"]=> string(10) "Supplier B" ["productName"]=> string(3) "ABC" } [2]=> array(2) { ["name"]=> string(10) "Supplier B" ["productName"]=> string(3) "DEF" } [3]=> array(2) { ["name"]=> string(10) "Supplier C" ["productName"]=> string(3) "XYZ" } [4]=> array(2) { ["name"]=> string(10) "Supplier D" ["productName"]=> string(3) "BBB" } [5]=> array(2) { ["name"]=> string(10) "Supplier E" ["productName"]=> string(6) "ABCDEF" } [6]=> array(2) { ["name"]=> string(10) "Supplier F" ["productName"]=> string(6) "ABCDEF" } }

preferences:
177.36 ms | 404 KiB | 184 Q