在foreach期间插入数组

I'm fairly certain the answer is no, but is it possible to insert something into an array during a foreach loop? Ideally at the very spot you are at in the array during the loop.

For example:

foreach($stock->StockData as &$stock) {    
        if($dateTime < $stock['DateTime']) {
            // INSERT NEW RECORD AT THIS SPOT IN THE ARRAY
        }   
}

As I say, I'm fairly certain the answer is no, but rather than build a new array, I just thought I'd ask.

I stand corrected!

http://docstore.mik.ua/orelly/webprog/php/ch05_07.htm

It apparently is just fine to do this in PHP.

According to the reference, PHP operates on a copy of the array when you start a foreach iterator, meaning that the iterator will not be corrupted by operations on the original array within the body of the foreach!

You really don't want to mutate an object is being iterated on. It will break your iterator/loop and could possibly crash the script/program by accessing or changing memory that you don't have access to anymore, possibly because array size has reduced.