unset within foreach

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Sun Oct 28, 2012 10:09 am

unset within foreach

Postby JoeB » Sun Nov 25, 2012 2:45 pm


Is it ok to unset elements in an array that is being iterated with foreach? e.g.

Code: Select all

$x = 0;
foreach($arData as $key => $value) {

  if( $key == "my_key_$x" ) {

I'm iterating through an array, looking for certain keys, then when they are found, i remove them and continue iterating.
Just wondered if this is ok?

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests