PHP changes the value in the loop

Source: Internet
Author: User
Php

foreach ($array as $key =>& $value) {            //If $value is also an array            //I want to split $value  For example enough to split 2 of this           $result = Array_ Slice ($value, 0,3);           $value of the next loop            =  array_slice ($value, 3);            Q:  How is the next loop array for  array_slice ($value, 3);        }


I just got in touch with PHP guys, help me.


Reply to discussion (solution)

foreach ($array as $key =>& $value) {foreach ($value as $key 2=>& $value 2) {foreach ($value 2 as $key 3=>& $value 3) {}}}

Upstairs, if I have other operations in the loop, it's going to be a hassle.

I want to
After $value split
and re-assign the $value.
Then prev ($array);
I don't know if that's possible. Testing

With recursion ...

Write a recursive method, and you're done.

No!
Since the array is passed in to foreach, it is not possible to manipulate its internal pointers externally.
You can use the For loop with Array_splice to implement

Maybe you can do it with arrayobject through an iterator, not done, not good.

If the array $array the loop, append the data.
This will eventually loop to the segmented array.
Have the above problem?

For Yes, but depends on the final value of the notation
foreach Can not

First use a foreach to put your segmented content into another array, and then the new array of foreach is not OK?

Or you can try the next (each ())

  • 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.