0

I can't bring out the genre (action and science fiction). I am using this $title = $array->movie->title; for the title and more, but with genre it's not working. Idea please ?

<!-- language-all: lang-json -->



stdClass Object
    (
        [movie] => stdClass Object
            (
                [code] => 27405
                [movieType] => stdClass Object
                    (
                        [code] => 4002
                        [$] => Long-métrage
                    )

                [originalTitle] => Oblivion
                [title] => Oblivion
                [keywords] => Horizons Oblivion Oblivion 
                [productionYear] => 2013
                [nationality] => Array
                    (
                        [0] => stdClass Object
                            (
                                [code] => 5002
                                [$] => U.S.A.
                            )

                    )

                [genre] => Array
                    (
                        [0] => stdClass Object
                            (
                                [code] => 13025
                                [$] => Action
                            )

                        [1] => stdClass Object
                            (
                                [code] => 13021
                                [$] => Science fiction
                            )

                    )
nice_dev
  • 17,053
  • 2
  • 21
  • 35
Boom
  • 41
  • 6
  • 1
    Why is `$` an object property name though? – nice_dev Nov 30 '20 at 05:13
  • $genre = $array->movie->genre->[0]->[$]; not working i'm bloqued mate :/ – Boom Nov 30 '20 at 05:16
  • genre is an array so it should be `$array->movie->genre[0]->code` – catcon Nov 30 '20 at 05:20
  • @Boom Ok, variable name should not be `$array` if what you have inside is a stdclass object. So, it will be `$array->movie->genre[0]->{'$'}`. IMO, you really need to fix property names and make it more readable. – nice_dev Nov 30 '20 at 05:22
  • There is solution and it's working :) https://stackoverflow.com/questions/29805011/decode-json-with-number-object-in-php Thanks you all Ps : $array = json_decode($result, TRUE); (associative) array ... – Boom Nov 30 '20 at 05:22
  • [echo implode(', ', array_column($object->movie->genre, '$'));](https://3v4l.org/KIG3H) – mickmackusa Nov 30 '20 at 06:51

0 Answers0