fork download
  1. <?php
  2.  
  3. $json = <<<JSON
  4.   [
  5.   {
  6.   "id": "1",
  7.   "clientid": "1",
  8.   "status": "2",
  9.   "duedate": "2017-09-05",
  10.   "company": "Cliente Exemplo",
  11.   "website": "clienteexemplo.com"
  12.   },
  13.   {
  14.   "id": "8",
  15.   "clientid": "1",
  16.   "status": "2",
  17.   "duedate": "2017-10-06",
  18.   "company": "Cliente Exemplo",
  19.   "website": "clienteexemplo.com"
  20.   },
  21.   {
  22.   "id": "15",
  23.   "clientid": "1",
  24.   "status": "2",
  25.   "duedate": "2017-11-06",
  26.   "company": "Cliente Exemplo",
  27.   "website": "clienteexemplo.com"
  28.   },
  29.   {
  30.   "id": "16",
  31.   "clientid": "1",
  32.   "status": "2",
  33.   "duedate": "2017-11-03",
  34.   "company": "Cliente Exemplo",
  35.   "website": "clienteexemplo.com"
  36.   },
  37.   {
  38.   "id": "17",
  39.   "clientid": "1",
  40.   "status": "2",
  41.   "duedate": "2017-11-03",
  42.   "company": "Cliente Exemplo",
  43.   "website": "clienteexemplo.com"
  44.   },
  45.   {
  46.   "id": "24",
  47.   "clientid": "1",
  48.   "status": "2",
  49.   "duedate": "2017-12-06",
  50.   "company": "Cliente Exemplo",
  51.   "website": "clienteexemplo.com"
  52.   },
  53.   {
  54.   "id": "31",
  55.   "clientid": "1",
  56.   "status": "2",
  57.   "duedate": "2018-01-06",
  58.   "company": "Cliente Exemplo",
  59.   "website": "clienteexemplo.com"
  60.   },
  61.   {
  62.   "id": "40",
  63.   "clientid": "1",
  64.   "status": "2",
  65.   "duedate": "2018-02-06",
  66.   "company": "Cliente Exemplo",
  67.   "website": "clienteexemplo.com"
  68.   },
  69.   {
  70.   "id": "47",
  71.   "clientid": "1",
  72.   "status": "2",
  73.   "duedate": "2018-03-06",
  74.   "company": "Cliente Exemplo",
  75.   "website": "clienteexemplo.com"
  76.   },
  77.   {
  78.   "id": "60",
  79.   "clientid": "1",
  80.   "status": "2",
  81.   "duedate": "2018-04-06",
  82.   "company": "Cliente Exemplo",
  83.   "website": "clienteexemplo.com"
  84.   },
  85.   {
  86.   "id": "61",
  87.   "clientid": "1",
  88.   "status": "4",
  89.   "duedate": "2018-05-06",
  90.   "company": "Cliente Exemplo",
  91.   "website": "clienteexemplo.com"
  92.   },
  93.   {
  94.   "id": "68",
  95.   "clientid": "1",
  96.   "status": "4",
  97.   "duedate": "2018-05-03",
  98.   "company": "Cliente Exemplo",
  99.   "website": "clienteexemplo.com"
  100.   }
  101.   ]
  102. JSON;
  103.  
  104. abstract class Status {
  105. const ATRASADO = 4;
  106. const EM_DIA = 2;
  107. }
  108.  
  109. $data = json_decode($json);
  110.  
  111. $atrasados = array_filter($data, function ($it) {
  112. return $it->status == Status::ATRASADO;
  113. });
  114.  
  115. print_r($atrasados);
Success #stdin #stdout 0.02s 23608KB
stdin
Standard input is empty
stdout
Array
(
    [10] => stdClass Object
        (
            [id] => 61
            [clientid] => 1
            [status] => 4
            [duedate] => 2018-05-06
            [company] => Cliente Exemplo
            [website] => clienteexemplo.com
        )

    [11] => stdClass Object
        (
            [id] => 68
            [clientid] => 1
            [status] => 4
            [duedate] => 2018-05-03
            [company] => Cliente Exemplo
            [website] => clienteexemplo.com
        )

)