Skip to content

Instantly share code, notes, and snippets.

@eoigal
eoigal / gist:430aca755a7e8cf24ae17d9d9bef36f3
Last active Aug 17, 2016
Find subset of associative array in PHP
View gist:430aca755a7e8cf24ae17d9d9bef36f3
<?php
$associative_array = ['firstname' => 'John', 'lastname' => 'Smith', 'DOB' => '2000-10-10', 'country' => 'Ireland' ];
$subset = array_intersect_key( $associative_array, array_flip( [ 'lastname', 'country' ] ) );
print_r( $subset );
// Outputs...
// Array ( [lastname] => Smith [country] => Ireland );