Determine if array B has a value in array a

Source: Internet
Author: User
Determine if array B has the value in array a
This post was last edited by xiangqiankun520 on 2014-12-11 04:19:34

Please ask your predecessors,
Two arrays of arr1 arr2
To implement, if there is a value for arr1 in arr2, the output arr2 already contains the value in ARR1

arr1 = Array ([0] = 7 [1] = 100);
ARR2 = Array ([0] = 2 [1] = 8 [2] = 9 [3] = = 1001 [4] = 7 );
if ( ) {
echo "ARR2 already contains the values in the arr1";
}



------to solve the idea----------------------
Intersection non-null
Count (Array_intersect ($A, $B)) >0
------to solve the idea----------------------
$arr 1 = Array (7, 100);
$arr 2 = Array (2, 8, 9, 1001, 7);
Print_r (Array_uintersect ($arr 1, $arr 2, "strcasecmp"));
------to solve the idea----------------------
Use the function Array_intersect to implement the function you want.
------to solve the idea----------------------
You'll know the intersection.

$arr 1 = Array (All-in-all);
$arr 2 = array (1,3,4,5);

Check ($arr 1, $arr 2);

function Check ($arr 1, $arr 2) {
$result = Array_intersect ($arr 1, $arr 2);
Print_r ($result);
}
  • 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.