1

I want to access, this array

(certification inside release_dates inside results)

  "results": [
   {
     "iso_3166_1": "IN",
     "release_dates": [
     {
        "certification": "U",
        "note": "",
     }
     ]
   }
   ]

I am using this code:

 if (isset($response4["results"]) && is_array($response4["results"])) 
 {
     foreach ($response4["results"] as $genreObject) 
     {
         $release_dates_iso_3166_1 = $genreObject["iso_3166_1"];
         $release_dates_certification = $genreObject["release_dates"]["certification"];
         $stmt->execute();
      } 
  } 

But this code only access iso_3166_! not certification

Error: Notice: Undefined index: certification

2 Answers 2

2

Because release_dates is array and you must be use first element of this array:

if (isset($response4["results"]) && is_array($response4["results"])) 
{
    foreach ($response4["results"] as $genreObject) 
    {
        $release_dates_iso_3166_1 = $genreObject["iso_3166_1"];
        $release_dates_certification = $genreObject["release_dates"][0]["certification"];

        $stmt->execute();
    } 
} 
Sign up to request clarification or add additional context in comments.

Comments

1

release_dates key contain arrays, not object. So you should iterate or access the keys.

if (isset($response4["results"]) && is_array($response4["results"])) {
    foreach ($response4["results"] as $genreObject) {
       $release_dates_iso_3166_1 = $genreObject["iso_3166_1"];
       $release_dates_certification = null;
       foreach ($genreObject["release_dates"] as $release_dates_elements) {
           $release_dates_certification = $release_dates_elements["certification"];
       }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.