Array_splice function result Assignment solution idea

Source: Internet
Author: User
Array_splice function Result Assignment
$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.
------to solve the idea----------------------
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.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.