php排除陣列中重複的值
$result=[“s”,”s”,”23″];
array_unique($result)
php陣列新增
array_push($result,”sss”,”sss”)
在第二個開始打要新增的變數或字串
php交集和差集
交集array_intersect() :
<?php
$array1 = array ("a" => "green", "red", "blue");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
?>
最後$result 變成:
Array找兩個陣列中共通元素
(
[a] => green
[0] => red
)
差集 array_diff():
<?php
$array1 = array ("a" => "green", "red", "blue", "red");
$array2 = array ("b" => "green", "yellow", "red");
$result = array_diff ($array1, $array2);
?>
結果是blue
找跟別的陣列中沒有的元素