mercredi 28 juin 2017

If-statement inside foreach, the statement is not applying

I'm processing a json from an url and showing some data. The problem is that I just want to display two accounts with certain id's but when I execute the following code is echoing the name of each account and not selecting the ones I choosen in the if-statement.

foreach ($data as $row) {

$id = $row->id;
$account = $row->account;
$time = date("Y-m-d H:i:s");

if ($id == 100) {echo $account;}
elseif ($id == 120) {echo $account;}
else {}

}

The Json is like

{"id":120,"Name":"Companytest"},{"id":121,"Name":"BensonTillis"},{"id":123,"Name":"JSBrothers"}

Thank you.

Aucun commentaire:

Enregistrer un commentaire