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

  • BASS212M

    BASS212M

    15 Temmuz 2009
  • campos9896

    campos9896

    24 Mart 2012
  • TrenchTech Computer Repair Tutorials

    TrenchTech C

    19 EYLÜL 2014