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) { return count(array_filter( $data, function ($match) use ($value) { return $match['productName'] === $value['productName']; } ) > 1); } ); var_dump($result);
based on nJ8CD
Output for 7.2.0
Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk on line 42 Warning: count(): Parameter must be an array or an object that implements Countable in /in/hR8tk 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.3.19 - 7.1.10
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" } }