Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

unset within foreach

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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?
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Oct 28, 2012 10:09 am

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.