Witam,
poprzedni temat dotyczy czegoś innego, więc proszę nie zamykać tego.
Bawiąc się otomoto i pobierając kategorie Allegro mam problem z poruszaniem się po tablicy obiektów stdObject. Oto kawałek tablicy wyświetlany dzięki print_r():
Array
(
[0] => stdClass Object
(
[id] => 4079
[name] => Inne pojazdy i Ĺodzie
[children] => Array
(
[0] => stdClass Object
(
[id] => 18500
[name] => Buggy
[children] => Array
(
)
)
[1] => stdClass Object
(
[id] => 18501
[name] => Gokarty
[children] => Array
(
)
)
[2] => stdClass Object
(
[id] => 4080
[name] => Ĺodzie
[children] => Array
(
[0] => stdClass Object
(
[id] => 8727
[name] => Jachty
[children] => Array
(
)
)
[1] => stdClass Object
(
[id] => 18507
[name] => Katamarany
[children] => Array
(
)
)
[2] => stdClass Object
(
[id] => 4084
[name] => MotorĂłwki
[children] => Array
(
)
)
[3] => stdClass Object
(
[id] => 18508
[name] => WiosĹowe
[children] => Array
(
)
)
Żeby pobrać pierwsze dane to wystarczy zrobić:
foreach($allegroCat as $id => $ele)
{
echo $allegroCat[$id]->{'id'}." - ".$allegroCar[$id]->{'name'};
}
Problem pojawia się gdy chcę pobrać listę "dzieci" jednego z wyników. Próbowałem zrobić tak:
$currentCat = $allegroCat[2]->{'children'};
I to jeszcze poprawnie działało, ale kolejny etap np.:
$currentCat = $currentCat[kolejne_id]->{'children'};
Nie daje żadnego rezultatu. Nie mam informacji o błędzie, oraz po próbie wypisania
print_r($currentCat);
jest pusty ekran. Oczywiście pod kolejne_id podaję wartość, która ma na pewno potomków.