Skip to content

Instantly share code, notes, and snippets.

@eoigal
eoigal / gist:430aca755a7e8cf24ae17d9d9bef36f3
Last active August 17, 2016 09:55
Find subset of associative array in PHP
<?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 );