3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array( array( 'Field1' => 'red', 'Field2' => 'green', 'Field3' => 'blue' ), array( 'Field1' => 'pink', 'Field2' => 'pinkish', 'Field3' => 'barbiecolor' ), array( 'Field1' => 'red', 'Field2' => 'blue', ' Field3' => 'orange' ) ); $searchBy = array( 'Field1' => 'red', 'Field2' => 'blue' ); // use($searchBy) function find($needle, $haystack) { $r = array(); foreach ( $haystack as $k => $a ) { array_intersect_assoc($needle, $a) == $needle and $r[$k] = $a; } return $r; } $find = find($searchBy, $array); print_r($find); ?>
Output for 4.3.0 - 7.1.0
Array ( [2] => Array ( [Field1] => red [Field2] => blue [ Field3] => orange ) )