This article mainly introduces the PHP delete array specified element implementation code related information, the need for friends can refer to the following
PHP Delete array Specifies the element implementation code
The function of deleting an array-specific element in PHP is not directly available, and most can only encapsulate the method
For example, the Array_slice () function takes a value out of a condition in an array and returns it.
Array_slice (Array,offset,length,preserve)
Array: Arrays
Offset: Specifies the starting position of the element to be removed. If it is a positive number, start with the previous one, and if it is negative, take the offset from the back to the absolute value.
<?php$a=array (0=> "Dog",1=> "Cat",2=> "Horse",3=> "Bird");p Rint_r (Array_slice ($a,));? >
Output
Array ([0] = Cat [1] = Horse)
There is also the Array_shift () function to delete the first element in the array and return the value of the deleted element.
The relative Array_pop () function deletes the last element in the array.
Several functions are used to feel Array_search () the utility Array_search () function, like In_array (), looks for a key value in the array. If the value is found, the key name of the matching element is returned. Returns false if not found
$array = Array (' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 '), $del _value = 3;unset ($array [Array_search ($del _value, $array)]);// Use unset to remove this element print_r ($array);
Output
Array (' 1 ', ' 2 ', ' 4 ', ' 5 ');
Thank you for reading, hope to help everyone, thank you for the support of this site!
The above is the whole content of this article, I hope that everyone's study has helped.