0

This notice show up in my localhost. For the first

data -> name

there is no problem displaying but the second data can not be display.

The notice

This is the code that I write, for some reason I have tried this code below but still not solve my problem.

$phase1 = $parsed_json->phases->phase1;

and also i tried

$phase1 = $parsed_json->{'phases'}->{'phase1'};

This is my code currently

<?php

$json = '{
    "name": "MCO",
    "phases": [
        {"phase1": "18-Mac-2020"}, 
        {"phase2": "1-April-2020"}
    ]
}';

$parsed_json = json_decode($json);

$name = $parsed_json->name;
$phase1 = $parsed_json->phases->phase1;

echo "Name: ".$name."<br/>";
echo "Phase 1: ".$phase1."<br/>";

?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    "phases" is an _array_ of objects. Either use a key to get a specific element: `$parsed_json->phases[0]->phase1` will print `18-Mac-2020`. Or loop over the elements – brombeer Jul 21 '20 at 04:15
  • Thank you so much! Now I understand the array of objects. Really great help. – Rohaizad Maznan Jul 21 '20 at 04:17

0 Answers0