Foreach question

From: Date: Tue, 05 Jul 2011 13:40:16 +0000
Subject: Foreach question
Groups: php.general 
Request: Send a blank email to php-general+get-313871@lists.php.net to get a copy of this message
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

« previous php.general (#313871) next »