note 16213 deleted from function.array-intersect by jimw

From: Date: Sat, 20 Oct 2001 18:47:35 +0000
Subject: note 16213 deleted from function.array-intersect by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19208@lists.php.net to get a copy of this message
someone might need to generate the parameter head of array_intersect in runtime (eg: not always the same number of arrays, or the same arrays...). i was looking and asking for a solution to this problem but noone could really give me anything more efficent (and shorter) than this one: //these are your arrays you want to intersect: $arr1=array("A","B","C","D","E"); $arr2=array("D","E","C","G","H","I","J"); $arr3=array("A","D","E","G","H","K"); $arr4=array("E","B","H","D","K","L"); //solution: D E //this is your function parameter-head, you can generate this however you want: $params="arr1,arr2,arr3,arr4"; $arr_arr=explode(",",$params); $anz=sizeof($arr_arr); for ($i=0;$i<$anz-1;$i++ ) { ${$arr_arr[$i+1]}=array_intersect(${$arr_arr[$i]},${$arr_arr[$i+1]}); }//for $intersect=${$arr_arr[$anz-1]}; foreach ($intersect as $elem ) { echo $elem." "; }//foreach maybe someone needs this, ... maybe not, maybe even you know a better and shorter way (let me know!!). cya, folks! lectrix.

« previous php.notes (#19208) next »