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

  • boburnham

    boburnham

    11 Temmuz 2006
  • Dan Gately

    Dan Gately

    13 AĞUSTOS 2006
  • soyacincautv

    soyacincautv

    14 NİSAN 2010