The result of the array_splice function is assigned $ arr1 = array (1, 2, 3 );
$ Arr2 = array (3, 4, 5 );
$ Arr1 = array_splice ($ arr2, 1, 1 );
Print_r ($ arr1 );
The result is Array ([0] => 4)
It is reasonable to say that the value assignment operator is executed only after the array_splice function is completed,
Then, the value in the array $ arr2 obtained by array_splice ($ arr2,) should be (3, 4 ),
Then calculate "=", and the content of the $ arr1 array should be (3, 4), but the entire
$ Arr1 = array_splice ($ arr2, 1, 1), but the content of the $ arr1 array is (4.
Reply to discussion (solution)
Why? What is your account?
Array_splice ($ arr2, 1st) deletes one element from the element of $ arr2 (counting starts from 0) and returns the deleted element.
You only want him to delete one, and he will never delete two
The array_slice () function extracts a value from the array based on the conditions and returns it.
You have not understood the meaning of this function ...... The code you write means that you can get a value from the second position of the array.
I want to use array_splice to delete the second digit of $ arr2 and assign it to $ arr1, and then display the values in the remaining array, then the code is written as $ arr1 = array_splice ($ arr2 ).
I don't understand the result. I think the definition of array_splice on the internet is to delete or replace the value of the specified part in the array, but $ arr1 = array_splice ($ arr2) the result of the code is the value I want to delete. is $ arr1 = array_splice ($ arr2, 1, 1) Equivalent to array_slice ($ arr2, 1, 1 )?
The number in the manual is clear: returns an array containing the removed unit
From the returned results, array_splice ($ arr2,) is equivalent to array_slice ($ arr2)
But the former has changed the original state of $ arr2.
Thank you on the 5th floor. I didn't understand the return value of this function in the document. I always thought that this function would return the remaining data of the original array. thank you.