itme php çok boyutlu Array

2 Cevap php

Bu çok boyutlu dizi array_push mümkün mü?

Kullanarak dizi oluşturma:

$ObjectArray = array();
$ShiftArray = array($ObjectArray);
$WeekShiftArray = array($ShiftArray);
$MasterShiftArray = array($WeekShiftArray);

Ve kullanarak diziye itmeye çalışıyor

array_push($MasterShiftArray[$last_monday_from_date][$CurrentShift->Offset][$CurrentShift->Shift], $CurrentShift);

Ama ben alıyorum:

Uyarı: array_push () parametre 1 hattı 94 / opt / lampp / htdocs / sandboxj / blog / wp-content / plugins / Güvenilmez / AddShift.php verilen dizi, nesne olmasını bekliyor

Herhangi bir yardım mutluluk duyacağız.

2 Cevap

Adından da anlaşılacağı gibi , $ Objectarray muhtemelen nesneleri bir dizi değil, dizilerin bir dizidir. Yani bir nesnenin içine değerleri zorlamaya çalışıyoruz.

EDIT
I'm assuming you're not showing the actual contents of $ObjectArray here BTW. Is this correct?

EDIT 2
Hmm, I've tested it now, and the levels you are addressing work fine with the example you're giving, even if the $objectArray holds objects. So there is probably something else going on here which we're not seeing.

Eğer $ Objectarray onu ele zamanda bir dizi olduğundan emin misiniz?

EDIT 3
What do you get when you do a var_dump( $ObjectArray ) right before the array_push call?

Sadece yapabilirdi

$MasterShiftArray[$last_monday_from_date][$CurrentShift->Offset][$CurrentShift->Shift][] = $CurrentShift;