Like this data, if I have a variable nid, how to traverse after going to know his name.
[ {
"Id": "T1SD",
"Name": "Xiaoxiao",
"Namea": "Test Look",
"NId": "CSD2"
}, {
"Id": "AE2",
"Name": "Zhang San",
"Namea": "Haha",
"NId": "20AF"
}, {
"Id": "c3p",
"Name": "User 1",
"Namea": "Dingding",
"NId": "4FC"
。。。。。。。。。。。。。。
} ]
I have such a group of data, and I do not know his specific length, so, it used me "... "To omit.
If I know a variable nid, how to go to the value of his name for the U-even.
For example, if I find a nid equals 4FC. How to get through the code to his name is "User 1";
Share to:
------Solution--------------------
$s =<<< TXT
[ {
"Id": "T1SD",
"Name": "Xiaoxiao",
"Namea": "Test Look",
"NId": "CSD2"
}, {
"Id": "AE2",
"Name": "Zhang San",
"Namea": "Haha",
"NId": "20AF"
}, {
"Id": "c3p",
"Name": "User 1",
"Namea": "Dingding",
"NId": "4FC"
} ]
TXT;
$nId = ' 4FC ';
$t = Json_decode ($s, true);
$r = Array_filter ($t, function ($a) use ($nId) {return $a [' nId '] = = $nId;});
Echo current ($r) [' Name '];
User 1