This is similar to the data. if I have a variable nId, how can I traverse it and know its name?

Source: Internet
Author: User
For data similar to this, if I have a variable nId, how can I traverse it and know its name. [& Nbsp; {& nbsp; "Id" & nbsp;: & nbsp; "t1sd", & nbsp; "Name" & nbsp ;: & nbsp; "xiaoxiao", & nbsp; "Namea" & nbsp;: & nbsp; similar to this data, if I have a variable nId, how to traverse and know his name.
[{
"Id": "t1sd ",
"Name": "xiaoxiao ",
"Namea": "Test appearance ",
"NId": "csd2"
},{
"Id": "ae2 ",
"Name": "Zhang San ",
"Namea": "Haha ",
"NId": "20af"
},{
"Id": "c3P ",
"Name": "User 1 ",
"Namea": "dingding ",
"NId": "4fc"
..............
}]

I have a set of data like this and I don't know the specific length of it. so I used "..." in it. .
If I know a variable nId, how do I get the value of its name.
For example, if I find an nId equal to 4fc. How can I get the name "user 1" through code? share it:
------ Solution --------------------
$ S = <TXT
[{
"Id": "t1sd ",
"Name": "xiaoxiao ",
"Namea": "Test appearance ",
"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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.