O
O
object_Object2022-01-10 14:11:31
PHP
object_Object, 2022-01-10 14:11:31

How to find out if there was such an array?

I welcome everyone!
There is this JSON

{
   "ok":true,
   "result":[
      {
         "var2":"fiudckj",
         "var215":"5",
         "received":{
            "from":"USERNAME1",
            "AMOUNT":10000,
            "message":"Subscribe to pewdiepie"
         },
         "sent":[
            
         ]
      },
      {
         "var2":"rhdjrvjkf",
         "var215":"562",
         "received":{
            "from":"USERNAME2",
            "AMOUNT":10000,
            "message":"Subscribe to pewdiepie"
         },
         "sent":[
            
         ]
      },
   ],
   "previous_transaction":{
      "var2":9610895000003,
      "var215":"101"
   }
}


How to find out if there is an array in this json in which from = USERNAME1 and AMOUNT = 12345678
the number of arrays in result is more than 30
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2022-01-10
@Rsa97

json_decode
foreach or array_filter

L
Leonid, 2022-01-10
@easycode

1) enumeration of array elements with comparison:

foreach ($json['result'] as $_item) {
 if ($_item['received']['from'] == 'USERNAME1' and $_item['received']['AMOUNT'] == '12345678')

2) the option for which they can shoot)))
if ( preg_match('|"from":"USERNAME1",\s"AMOUNT":12345678,|is', $json, $match) )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question