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

  • Brandon McCrary

    Brandon McCr

    15 Ocak 2012
  • ShotgunSandwichENT

    ShotgunSandw

    3 EKİM 2012
  • Tina Chen

    Tina Chen

    26 Mayıs 2012