Hi all,

 

I've bumped into an interesting thing with foreach. I really don't know, if
this is normal working, or why it is, so I got curious.

 

The script:

 

foreach ( $cats as &$c ) {

               echo $c['id'];

               if ( $c['id'] < 5 ) {

                              $c['id']++;

                              $cats[] = $c;

               }

}

 

Input 1:

 

$cats = array( array( 'id' => 1 ) );

 

Output 1:

 

1

 

Input 2:

 

$cats = array( array( 'id' => 1 ), array( 'id' => 2 ) );

 

Output 2:

 

122334455

 

 

Why is this? Is this normal behaviour?

 

 

Thanks,

 

               Tamas

Reply via email to