This article mainly introduces the PHP difference set operation function Array_diff and the array traversal, the interest friend's reference, hoped to be helpful to everybody.
In this paper, we describe the method of the PHP associative array to delete elements based on the element values, as follows:
<?php $array 1 = Array ("A" = "green", "Red", "Blue", "Red"); $array 2 = Array ("b" = "green"); $result = Array_diff ($array 1, $array 2);//This is equivalent to deleting the element with the value "green" in $array1. Print_r ($result);?>
There is a more complex method than the one above, but the effect is the same:
Function Removearrayelement (& $ar, $val) {$tmp = array (); foreach ($ar as $k + = $arc) { if ($arc! = $val) { $tmp [$k]= $arc; }} $ar = $tmp; unset ($tmp);}
Summary: the above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
Implementation techniques of PHP unordered tree
Implementation techniques of PHP unordered tree
PHP Process Control and mathematical operations