Solution to phparray_splice function usage

Source: Internet
Author: User
To put it simply, the array_splice () function removes the array elements starting from a certain position in the given array and returns an array containing the removed units. Therefore, your negligence is: simply put, the array_splice () function removes the array elements starting from a certain position in the given array, returns an array containing the removed cells. Therefore, your negligence lies in:

Foreach (array_splice ($ array, 2) as $ key => $ value)

In this code, the result of array_splice ($ array, 2) is the elements that are removed from the array, rather than the data you want to retain.

You need to take a closer look at the prototype declaration of array_splice:

Array array_splice (array & $ input, int $ offset .....)

Note: The & $ input parameter is transmitted by address instead of the normal value. Therefore, after calling the array_splice function, the data in the $ input array is directly modified.

In summary, the modified code is as follows:

 $ Value) {echo "$ key: $ value
";}?>

The above is the solution of php array_splice function. For more information, see PHP Chinese website (www.php1.cn )!

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.