title: Echo specific elements JSON to Array
body: <p>Hi I'm trying to echo specific elements from the following JSON. </p>
  
  <p>I've tried first to print everything with the following and it works.         </p>
  
  <pre><code>$obj1 = json_decode($str, true);
  echo $str;
  </code></pre>
  
  <p>But what I want is to print each player with his name and shirt number.</p>
  
  <p>teams->home->players->name->forename</p>
  
  <p>teams->home->players->name->surname</p>
  
  <p>teams->home->players->shirt</p>
  
  <p>I've tried different things but every time I get an error like the following </p>
  
  <p>Notice: Trying to get property of non-object</p>
  
  <pre><code>{
    "teams": {
      "home": {
        "id": "528",
        "formation": "4212",
        "players": [
          {
            "id": "8576",
            "name": {
              "surname": "Isco"
            },
            "shirt": "22"
          },
          {
            "id": "5886",
            "name": {
              "initial": "K",
              "forename": "Karim",
              "surname": "Benzema"
            },
            "shirt": "9"
          },
          {
            "id": "136",
            "name": {
              "initial": "C",
              "forename": "Cristiano",
              "surname": "Ronaldo"
            },
            "shirt": "7"
          }
        ],
        "subs": [
                  {
            "id": "188",
            "name": {
              "initial": "N",
              "forename": "Nathaniel",
              "surname": "Clyne"
            },
            "shirt": "2"
          }
      ]
      }
    }
  }
  </code></pre>
  
  <p>I will appreciate it if anyone helps me with this.</p>
  
  <p>Thanks</p>