Ignore element in JSON with PHP

0

Let's say we have a JSON with 2 elements below:

    exemplo: { 
    [{
    "arquivo": "Arquio 1",
    "size": "2340"
    }, {
    "arquivo": "Arquivo 2",
    "size": "0"
     }, {
     "arquivo": "arquivo 3",
     "size": "4329"
     }
  

Use for () PHP to list the files.

For example:

    for($i=0; $i<=10; $i++)
    {
    $arquivo = $json->exemplo[$i]->arquivo;
    $size = $json->exemplo[$i]->size;

    echo "Nome: ".$nome." - ".$size."<br />";
    }

What I want to do is to ignore files from the list that has size "0" and leave only those larger than 0 before moving on to PHP.

Can anyone help me?

    
asked by anonymous 19.04.2016 / 23:50

1 answer

2

This should work:

for($i=0; $i<=10; $i++)
{
  $arquivo = $json->exemplo[$i]->arquivo;
  $size = $json->exemplo[$i]->size ;

  if ((int)$json->exemplo[$i]->size < 1) {
      unset($json->exemplo[$i]);

  } else {
      echo "Nome: ".$nome." - ".$size."<br />";
  }
}
    
19.04.2016 / 23:57