$arr 1 = Array (All-in-all);
$arr 2 = array (3,4,5);
$arr 1 = array_splice ($arr 2,1,1);
Print_r ($arr 1);
The result is an array ([0] = 4)
In a logical sense, the assignment operator does not take place until the Array_splice function is finally completed.
Then Array_splice ($arr 2,1,1) Gets the value within the array $arr2 should be (3,4),
Then the operation "=", then get the contents of the $ARR1 array should be (3,4), but actually run the entire
$arr 1 = array_splice ($arr 2,1,1), but the contents of the $ARR1 array are (4), solved.
Reply to discussion (solution)
Why, what's your account?
Array_splice ($arr 2,1,1) removes 1 elements from the 1th element of $arr 2 (count starting from 0) and returns the deleted element
You only let him delete 1, he will not be the one who has to cut 2.
The Array_slice () function takes a value out of the array and returns it as a condition.
You don't understand the meaning of this function ... You write code that means, starting at the second position of the array, taking a value
Upstairs, my intention is to use Array_splice to remove the second bit of $ARR2 and assign it to $ARR1, then display the values in the remaining array, and then write the code in handy: $arr 1 = array_splice ($arr 2,1,1).
I do not understand the results, I think the online definition of array_splice is to delete or replace the value of the specified part of the array, but the result of $arr1 = Array_splice ($arr 2,1,1) is the value I want to delete, whether $ARR1 = array _splice ($arr 2,1,1) equivalent to Array_slice ($arr 2,1,1)?
The number in the handbook is clear: Returns an array containing the removed cells
Array_splice ($arr 2,1,1) is equivalent to Array_slice ($arr 2,1,1) only from the returned results
But the former has changed the original state of $arr 2.
Thank you, 5 floor. The return value of this function is not understood in the information book, but it is always assumed that this function returns the remaining data from the original array, thank you.