note 24545 modified in function.array-keys by vrana

From: Date: Tue, 17 Aug 2004 13:58:36 +0000
Subject: note 24545 modified in function.array-keys by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79769@lists.php.net to get a copy of this message
Here is a way to use array_intersect on array keys rather than values: <?php $a = array("apple" => "red", "banana" => "yellow"); $z = array("apple" => "green", "peach" => "orange", "banana" => "rotten"); $intersected_keys = array_intersect(array_keys($a), array_keys($z)); print_r($intersected_keys); ?> This will print: Array ( [0] => apple [1] => banana ) --was-- Here is a way to use array_intersect on array keys rather than values: $a = array("apple" => "red", "banana" => "yellow"); $z = array("apple" => "green", "peach" => "orange", "banana" => "rotten"); $intersected_keys = array_intersect(array_keys($a), array_keys($z)); print_r($intersected_keys); This will print: Array ( [0] => apple [1] => banana ) http://php.net/manual/en/function.array-keys.php

« previous php.notes (#79769) next »