I have been working on a project to automatic fetch information from a client page. Its basically a function that call a bunch of other functions and arrange the information in an stdClass Object. I thought I was clever and made it "searchable" but I have encountered some small problems.
Here is an example of the output:
stdClass Object
(
[ud] => stdClass Object
(
[name] => stdClass Object
(
[svenska] => Uddev
[engelska] => uddev
)
[biografer] => stdClass Object
(
[0] => stdClass Object
(
[namn] => Drottning. Uddev
[id] => 196
[salonger] => stdClass Object
(
[0] => stdClass Object
(
[salong] => Vag 1
[platser] => 100 platser
[ljud] => SOU
)
[1] => stdClass Object
(
[salong] => Vag 2
[platser] => 100 platser
[ljud] => SOU
)
[2] => stdClass Object
(
[salong] => Vag 3
[platser] => 60 platser
[ljud] => SOU
)
[3] => stdClass Object
(
[salong] => Vag 4
[platser] => 50 platser
[ljud] => SOU
)
[4] => stdClass Object
(
[salong] => Vag 5
[platser] => 50 platser
[ljud] => DOLBY
)
[5] => stdClass Object
(
[salong] => Vag 6
[platser] => 34 platser
[ljud] =>
)
)
)
)
)
[ma] => stdClass Object
(
...... And the following object
As you can see, the index (or is it the key) for the first object is ud
.
I thought that i could do something like this:
$test = $crawler->fetchAllArray();
foreach ($test as $key => $value) {
if($key == 'ud'){
foreach ($value->{ud} as $child => $ud) { # line 295
echo "id: $key" . ", name: $ud->name->svenska";
}
}
}
And that would generate id: ud, name: Uddev
, but I receive the following error:
Notice: Use of undefined constant ud - assumed 'ud' in test.php on line 295
Notice: Undefined property: stdClass::$ud in test.php on line 295
Warning: Invalid argument supplied for foreach() in test.php on line 295
How do I properly echo the information from a specific object?