Printing emails from json objects with php
<p>I am trying to simply write all of these emails in a text file seperated with a comma like so</p>

<p><code>email1@email.com, email2@email.com, etc</code></p>

<p>I am new to php and now sure why I keep getting this parse error. I tried many things with all fails. Please help</p>

<pre><code>&lt;?php
$s = '{
  "-KNWTldOkA_WkT50a_aS" : {
    "Email" : "user@test.com",
    "num" : 3

  },
  "-KNi22_ZC7PlnDJkR4px" : {
    "Email" : "userEmailx@gmail.com",
    "num" : 10

  }
}';

$j = json_decode($s, true);
echo $j['-KNWTldOkA_WkT50a_aS']['Email'] . ',';

$file = fopen("emails.txt","w");

foreach ($j as $a) {
    var email = $a['Email'] . ',';
    fwrite($file, email);
}

fclose($file);
</code></pre>