note 113332 added to function.array-intersect-key

From: Date: Sat, 28 Sep 2013 08:08:51 +0000
Subject: note 113332 added to function.array-intersect-key
Groups: php.notes 
Request: Send a blank email to php-notes+get-196398@lists.php.net to get a copy of this message
in case you came here looking for a function that returns an array containing the values of all arrays with intersecting keys: <?php function array_merge_on_key($key, $array1, $array2) { $arrays = array_slice(func_get_args(), 1); $r = array(); foreach($arrays as &$a) { if(array_key_exists($key, $a)) { $r[] = $a[$key]; continue; } } return $r; } // example: $array1 = array("id" => 12, "name" => "Karl"); $array2 = array("id" => 4, "name" => "Franz"); $array3 = array("id" => 9, "name" => "Helmut"); $array4 = array("id" => 10, "name" => "Kurt"); $result = array_merge_on_key("id", $array1, $array2, $array3, $array4); echo implode(",", $result); // => 12,4,9,10 ?> ---- Server IP: 69.147.83.199 Probable Submitter: 81.210.250.58 ---- Manual Page -- http://php.net/manual/en/function.array-intersect-key.php Edit -- https://master.php.net/note/edit/113332 Del: integrated -- https://master.php.net/note/delete/113332/integrated Del: useless -- https://master.php.net/note/delete/113332/useless Del: bad code -- https://master.php.net/note/delete/113332/bad+code Del: spam -- https://master.php.net/note/delete/113332/spam Del: non-english -- https://master.php.net/note/delete/113332/non-english Del: in docs -- https://master.php.net/note/delete/113332/in+docs Del: other reasons-- https://master.php.net/note/delete/113332 Reject -- https://master.php.net/note/reject/113332 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196398) next »