PHP changes the value in the loop

Source: Internet
Author: User
PHP changes the value of the loop PHP

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


I just got in touch with PHP. can you help me?


Reply to discussion (solution)

foreach($array as $key=>&$value){foreach($value as $key2=>&$value2){foreach($value2 as $key3=>&$value3){}}}

If I have other operations in the loop upstairs, it will be very troublesome.

I want
$ Value after Segmentation
Then assign a value to $ value.
Then prev ($ array );
I don't know if this is feasible. I'm testing it.

Recursion...

Write a recursive method.

No!
Because after the array is passed into foreach, it cannot control its internal pointer externally.
You can use the for loop with array_splice

It may be possible to use ArrayObject to implement it through the iterator. it is hard to say that it has never been done.

What if we append data to the array $ array of the loop?
In this way, the split array will be recycled.
Is there any of the above problems?

Yes, but it depends on the final value.
Foreach is not allowed

First, use a foreach to put the content you split into another array, and then the new foreach array won't be enough?

Or you can try while (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.