[ {
"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";
Reply to discussion (solution)
What format is the data?
If you only have such a data, then you can only traverse it.
foreach ($arr as $data) {
if ($data [' nId ']== ' 4FC ') {
echo $data [' Name '];
Break
}
}
If the number of lookups is greater and the amount of data is large, it is recommended that you make an index first.
$nId _array = Array ();
foreach ($arr as $data) {
$nId _array [$data [' nId ']] = $data [' Name '];
}
And then every time you find it from this $nId _array.
$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