Two-dimensional array with identical judgment values

Source: Internet
Author: User
The two-dimensional array has the same judgment value $ arrayarray (array (pid & gt; 1, name & gt; a), array (pid & gt; 2, name & gt; B ), array (pid & gt; 3, name & gt; c), array (pid & gt; 1, name & gt; a), array (pid & gt; 4, the name and two-dimensional array have the same judgment value
$ Array = array ('pid '=> 1, 'name' => a), array ('pid' => 2, 'name' => B ), array ('pid '=> 3, 'name' => c), array ('pid' => 1, 'name' => ), array ('pid '=> 4, 'name' => d ));
For a two-dimensional array like this, how can we determine the value equal to the pid and name (for example, the value ('pid '=> 1, 'name' => a) in the example)
If yes, exit.

------ Solution --------------------
PHP code
$ Array = array ('pid '=> 1, 'name' => 'A'), array ('pid' => 2, 'name' => 'B'), array ('pid '=> 3, 'name' => 'C'), array ('pid' => 1, 'name' => 'A'); $ tmp = array (); foreach ($ array as $ k => $ v) {if (! $ Tem [$ v [pid]. '_'. $ v [name]) {$ tem [$ v [pid]. '_'. $ v [name] = $ v; print_r ($ v) ;}else {exit ;}}
------ Solution --------------------
PHP code
$ Array = array ('pid '=> 1, 'name' => 'A'), array ('pid' => 2, 'name' => 'B'), array ('pid '=> 3, 'name' => 'C'), array ('pid' => 4, 'name' => 'D'), array ('pid '=> 5, 'name' => 'e'), array ('pid' => 1, 'name' => 'A'), array ('pid '=> 4, 'name' => 'D'); $ idList = array (); foreach ($ array as $ key => $ value) {$ idList [] = implode (',', $ value);} $ idList2 = array_diff_assoc ($ idList, array_unique ($ idList); foreach ($ idList2 as $ key => $ value) {$ akey = array_search ($ value, $ idList); echo 'repeated array :'; print_r ($ array [$ akey]);}

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.