3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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) { echo 'TEST', PHP_EOL; return count(array_filter( $data, function ($match) use ($value) { echo $match['productName'], ' => ', $value['productName'], PHP_EOL; return $match['productName'] === $value['productName']; } ) > 1); } ); var_dump($result);
based on hR8tk
Output for 7.2.0
TEST ABC => ABC ABC => ABC DEF => ABC XYZ => ABC BBB => ABC ABCDEF => ABC ABCDEF => ABC Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => ABC ABC => ABC DEF => ABC XYZ => ABC BBB => ABC ABCDEF => ABC ABCDEF => ABC Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => DEF ABC => DEF DEF => DEF XYZ => DEF BBB => DEF ABCDEF => DEF ABCDEF => DEF Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => XYZ ABC => XYZ DEF => XYZ XYZ => XYZ BBB => XYZ ABCDEF => XYZ ABCDEF => XYZ Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => BBB ABC => BBB DEF => BBB XYZ => BBB BBB => BBB ABCDEF => BBB ABCDEF => BBB Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => ABCDEF ABC => ABCDEF DEF => ABCDEF XYZ => ABCDEF BBB => ABCDEF ABCDEF => ABCDEF ABCDEF => ABCDEF Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 TEST ABC => ABCDEF ABC => ABCDEF DEF => ABCDEF XYZ => ABCDEF BBB => ABCDEF ABCDEF => ABCDEF ABCDEF => ABCDEF Warning: count(): Parameter must be an array or an object that implements Countable in /in/7O30Y on line 44 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.3.19 - 7.1.10
TEST ABC => ABC ABC => ABC DEF => ABC XYZ => ABC BBB => ABC ABCDEF => ABC ABCDEF => ABC TEST ABC => ABC ABC => ABC DEF => ABC XYZ => ABC BBB => ABC ABCDEF => ABC ABCDEF => ABC TEST ABC => DEF ABC => DEF DEF => DEF XYZ => DEF BBB => DEF ABCDEF => DEF ABCDEF => DEF TEST ABC => XYZ ABC => XYZ DEF => XYZ XYZ => XYZ BBB => XYZ ABCDEF => XYZ ABCDEF => XYZ TEST ABC => BBB ABC => BBB DEF => BBB XYZ => BBB BBB => BBB ABCDEF => BBB ABCDEF => BBB TEST ABC => ABCDEF ABC => ABCDEF DEF => ABCDEF XYZ => ABCDEF BBB => ABCDEF ABCDEF => ABCDEF ABCDEF => ABCDEF TEST ABC => ABCDEF ABC => ABCDEF DEF => ABCDEF XYZ => ABCDEF BBB => ABCDEF ABCDEF => ABCDEF ABCDEF => ABCDEF 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" } }