SORU
21 ŞUBAT 2010, Pazar


Nasıl sil foreach döngü içinde dizi nesne için?

Nesneleri bir dizi üzerinden yineleme ve nesneleri dayalı bir 'ıd' özelliği, ama benim kod çalışmıyor. silmek istiyorum

foreach($array as $element) {
    foreach($element as $key => $value) {
        if($key == 'id' && $value == 'searched_value'){
            //delete this particular object from the $array
            unset($element);//this doesn't work
            unset($array,$element);//neither does this
        } 
    }
}

Herhangi bir öneri. Teşekkürler.

CEVAP
21 ŞUBAT 2010, Pazar


foreach($array as $elementKey => $element) {
    foreach($element as $valueKey => $value) {
        if($valueKey == 'id' && $value == 'searched_value'){
            //delete this particular object from the $array
            unset($array[$elementKey]);
        } 
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Eric Anthony

    Eric Anthony

    13 AĞUSTOS 2011
  • LimeFire

    LimeFire

    2 ŞUBAT 2012
  • ThePhestor

    ThePhestor

    22 Mart 2011