$a = array("a","b","c");
$b = array("b","c","d");
$c = array("c","d","e");
以上的$a,$b,$c會有隨機多個,接下來要在這幾個陣列做交集(array_intersect),請教各位前輩,有没有辨法做一個直接包含這三個(其實是隨機多個)陣列名稱的變數,放進array_intersect()內的陣列參數,如:(以下方法是失敗的 ???)
$dd='$a,$b,$c';
array_intersect($dd);
因為你放進去的不是陣列啊,
如果你要用不確定數量的陣列,
應該可以自己寫一個方法,
然後再來呼叫array_intersect.
$a = array("a","b","c");
$b = array("b","c","d");
$c = array("c","d","e");
$all = array($a, $b, $c);
//方法一
$result = array_intersect(...$all);
var_dump($result);
//方法二
$result = call_user_func_array('array_intersect', $all);
var_dump($result);