Method One:
Copy CodeThe code is as follows:
$arr 1 = Array (1, 3, 5,7,8);
$key = Array_search (3, $arr 1);
if ($key!== false)
Array_splice ($arr 1, $key, 1);
Var_dump ($arr 1);
?>
Output:
Array (4) {[0]=> int (1) [1]=> int (5) [2]=> int (7) [3]=> int (8)}
Method Two:
Copy the Code code as follows:
$arr 2 = Array (1, 3, 5,7,8);
foreach ($arr 2 as $key = $value)
{
if ($value = = = 3)
unset ($arr 2[$key]);
}
Var_dump ($arr 2);
?>
Output:
Array (4) {[0]=> int (1) [2]=> int (5) [3]=> int (7) [4]=> int (8)}
Summary: You can see the difference between using Array_splice () to remove a specific value and using unset to remove a specific value.
If the Array_splice () function is deleted, the index value of the array also changes.
If the unset () function is removed, the index value of the array does not change.
http://www.bkjia.com/PHPjc/328026.html www.bkjia.com true http://www.bkjia.com/PHPjc/328026.html techarticle method One: Copy the code as follows: PHP $arr 1 = array (1,3, 5,7,8), $key = Array_search (3, $arr 1), if ($key!== false) Array_splice ($arr 1, $key, 1); Var_dump ($arr 1);? Output: ...