Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 122011
 

How to remove object from array inside foreach loop?

Answer:

In PHP, to remove object (e.g. with the key = foo in the following example) from array inside foreach loop, you can try:

<?php

foreach($array as $key=> $value) {
    if ($key == "foo") {
        unset($array[$key]);
    }
}

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>