After some modifications and improvements, the effect
- $array1 = array("a" => "green", "red", "blue", "red");
- $array2 = array("b" => " green");
- $result = array_diff($array1, $array2);//This is equivalent to deleting the element with the value "green" in $array1.
- print_r($result);
- ?>
- /* There is another method, which is more complicated than the above, but the effect is the same. */
- removefunctionArrayElement(&$ar,$val)
- {
- $tmp = array();
- foreach($ar as $k => $arc)
- {
- if($arc!=$val)
- {
- $tmp[$k]=$arc;
- }
- }
- $ar = $tmp;
- unset($tmp);
- }
Copy code
|