PHP retrieves the first element of the array and deletes the array instance. In php, arrays are a special array type that can store various types of data. next I will introduce some instances for reading and deleting specified array elements from arrays. Array: array off array in php is a special array type that can store various types of data. next I will introduce some instances for reading and deleting specified array elements from arrays.
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.
I. PHP retrieves the first index array
It is very easy to retrieve the first element of the index array. you just need to write 0 as the subscript.
I would like to share with you the first method of getting the join array from PHP. First, put the code I wrote today:
The code is as follows: |
|
// Obtain the default First Channel name $ Channel_arr = $ this-> get_from_channel (); // array of all channels $ Arr_num = count ($ channel_arr ); $ First_channel = array_slice ($ channel_arr, 0,-($ arr_num-1); // obtain the first channel array $ Html ['from _ channel'] = $ first_channel [0]; |
Delete an array
The code is as follows: |
|
$ 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.
I think array_search () is more practical when using several functions.
The array_search () function is the same as the in_array () function. you can find a key value in the array. If this value is found, the key name of the matching element is returned. If not found, false is returned.
The code is as follows: |
|
$ 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 '); |
Delete an element in the array in PHP
To delete an array element in PHP, you can use the following methods:
To delete an element, use onset ()
The code is as follows: |
|
Unset ($ array [3]); Unset ($ array ['foo']); |
To delete multiple discontinuous elements, use unset ()
The code is as follows: |
|
Unset ($ array [3] $ array [5]); Unset ($ array ['foo'] $ array ['bar']); |
To delete multiple consecutive elements, use array_splice ()
The code is as follows: |
|
Array_splice ($ array $ offset $ length ); |
Bytes. Array: array off...