Php deletes the implementation code of specified elements in the array, and php array element code
Php code used to delete specified elements of an array
In PHP, functions that delete specified elements of an array are not directly usable. Most functions can only encapsulate the elements.
For example, the array_slice () function extracts a value from the Array Based on the Conditions and returns the result.
Array_slice (array, offset, length, preserve)
Array: array
Offset: Specifies the start position of the retrieved element. If it is a positive number, it is taken from the beginning to the end. If it is a negative value, it is taken from the back to the absolute value of the offset.
<? Php $ a = array (0 => "Dog", 1 => "Cat", 2 => "Horse", 3 => "Bird "); print_r (array_slice ($ a, 1, 2);?>
Output
Array ([0] => Cat [1] => Horse)
The array_shift () function also deletes the first element in the array and returns the value of the deleted element.
The relative array_pop () function deletes the last element in the array.
Several functions are used to find a key value in the array like in_array () in the array_search () function. If this value is found, the key name of the matching element is returned. If not found, false is returned.
$ Array = array ('1', '2', '3', '4', '5'); $ del_value = 3; unset ($ array [array_search ($ del_value, $ array)]); // use unset to delete this element print_r ($ array );
Output
Array ('1', '2', '4', '5 ');
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!