M
M
MikEeWay2018-04-03 21:00:00
PHP
MikEeWay, 2018-04-03 21:00:00

How to use the required array in JSON?

My JSON has multiple arrays. How to use the value of one array to make it clear that further sampling should be done from it?
json example

JSON
{
"data":[
    {
    "txnId":12615777480,
    "personId":777777,
    "date":"2018-04-01T21:01:51+03:00",
    "errorCode":0,
    "error":null,
    "status":"SUCCESS",
    "type":"IN",
    "statusText":"Success",
    "trmTxnId":"322605711",
    "account":"+7666666",
  "sum":{
    "amount":1,
    "currency":643
  },
  "commission":{
    "amount":0,
    "currency":643
  },
  "total":{
    "amount":1,
    "currency":643
  },
  "provider":{
    "id":7,
    "shortName":"QIWI Кошелек",
    "longName":"QIWI Кошелек",
    "logoUrl":null,
    "description":null,
    "keys":"мобильный кошелек, кошелек, перевести деньги, личный кабинет, отправить деньги, перевод между пользователями",
    "siteUrl":null,
    "extras":[
    ]
  },
    "source":null,
    "comment":"77098646",
    "currencyRate":1,
    "paymentExtras":[
    ],
  "features":{
    "chequeReady":false,
    "bankDocumentReady":false,
    "regularPaymentEnabled":false,
    "bankDocumentAvailable":false,
    "repeatPaymentEnabled":false,
    "favoritePaymentEnabled":false,
    "greetingCardAttached":false
  },
  "serviceExtras":{
  },
    "view":{
    "title":"QIWI Кошелек",
    "account":"+7666666"
    }
  },
{},
{},
{},
{},
{},
{},
{},
{},
{
    "txnId":12463731627,
    "personId":7777777,
    "date":"2018-03-10T10:34:19+03:00",
    "errorCode":0,
    "error":null,
    "status":"SUCCESS",
    "type":"IN",
    "statusText":"Success",
    "trmTxnId":"320667259",
    "account":"+76666666",
  "sum":{
    "amount":1,
    "currency":643
  },
  "commission":{
    "amount":0,
    "currency":643
  },
  "total":{
    "amount":1,
    "currency":643
  },
  "provider":{
    "id":7,
    "shortName":"QIWI Кошелек",
    "longName":"QIWI Кошелек",
    "logoUrl":null,
    "description":null,
    "keys":"мобильный кошелек, кошелек, перевести деньги, личный кабинет, отправить деньги, перевод между пользователями",
    "siteUrl":null,
    "extras":[
    ]
  },
  "source":null,
  "comment":"56732049",
  "currencyRate":1,
  "paymentExtras":[
  ],
  "features":{
    "chequeReady":false,
    "bankDocumentReady":false,
    "regularPaymentEnabled":false,
    "bankDocumentAvailable":false,
    "repeatPaymentEnabled":false,
    "favoritePaymentEnabled":false,
    "greetingCardAttached":false
    },
  "serviceExtras":{
  },
  "view":{
    "title":"QIWI Кошелек",
    "account":"+76666666"
    }
  }
  ],
  "nextTxnId":12461755984,
  "nextTxnDate":"2018-03-09T22:16:42+03:00"
}

Example of my code
$comment = 77098646;
$results = array_filter($object['data'], function ($item) use ( $comment ) {
  return $item['comment'] == $comment;
});
$status = $results ? 1 : 0;
  if($status == 1){
    echo '<br/>=)';
  }
else
  { 
    echo '<br/>=(';
  }

If commentequal 77098646, how to make it clear that further sampling should be done here? not where commentequal56732049
$results1 = array_filter($object['data'], function ($item1) use ( $amount, $comment) {
  return $item1['sum']['amount'] == $amount and $comment;
});
//var_dump($results1);
$status1 = $results1 ? 1 : 0;
  if($status1 == 1){
    echo '<br/>=))';
  }
else
  { 
    echo '<br/>=((';
  }

It is necessary that sum->amount be exactly from where comment is 77098646

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2018-04-03
@MikEeWay

If comment is equal to 77098646 how to make it clear that further sampling should be done here?

Use $results

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question