Deletes a value element from an array. Delete a value element in the array. This instance uses the phparray_diff function to delete a value element in the array, the method is simple. use the foreach and array_diff functions to delete a value element from an array. In this example, use the php array_diff function to delete a value element from the array, the method is simple. add the array_diff function with foreach.
Deletes a value element from an array.
This example uses the array_diff function in the php Tutorial to delete a value element in the array. the method is simple: use foreach and add the array_diff function.
*/
$ A1 = array ('blue', 'red', 'www .bkjia.com '), array ('black', 'Pink', 'green '));
$ A2 = array ('AAA', 'Pink', 'bbbbb ');
$ Str = 'red ';
$ A2 [] = $ str;
Foreach ($ a1 as $ key => $ value)
{
$ A1 [$ key] = array_diff ($ value, $ a2 );
}
Print_r ($ a1 );
// Simpler method
Foreach (array_diff ($ a1, $ a2) as $ _ key_1 ){
$ Arr_new [$ _ key_1] = $ arr_1 [$ _ key_1];
}
/*
The result is as follows:
Array
(
[0] => array
(
[0] => blue
[2] => yellow
)
[1] => array
(
[0] => black
[2] => green
)
)
Array_diff syntax
Array array_diff (array $ array1, array $ array2 [, array $...])
Returns a difference between array1 and array2.
*/
$ Array1 = array ("a" => "green", "php100.com", "blue", "red ");
$ Array2 = array ("B" => "green", "yellow", "red ");
$ Result = array_diff ($ array1, $ array2 );
Print_r ($ result );
/*
Array
(
[1] => blue
)
The array_diff function is used to delete a value element in the array. the method is simple: use the foreach function and the array_diff function to delete a value element in the array...