Determine whether array B exists in array.

Source: Internet
Author: User
Judge whether array B exists the value in array A. this post is edited by xiangqiankun520 at 2014-12-110. ask your predecessors for the two arrays arr1 & nbsp; arr2, if arr2 contains A value of arr1, the output arr2 contains the value of arr1 & nbsp; Array (& nb determines whether Array B has A value in Array.

This post was last edited by xiangqiankun520 at 04:19:34

Ask your predecessors,
Two arrays: arr1 arr2
To achieve this, if a value of arr1 exists in arr2, the output arr2 contains the value of 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 value in arr1 ";
}



------ Solution ----------------------
Intersection is not empty
Count (array_intersect ($ A, $ B)> 0
------ Solution ----------------------
$ Arr1 = Array (7,100 );
$ Arr2 = Array (2, 8, 9, 1001, 7 );
Print_r (array_uintersect ($ arr1, $ arr2, "strcasecmp "));
------ Solution ----------------------
Use the array_intersect function to implement the functions you want.
------ Solution ----------------------
The intersection will be known.

$arr1 = array(1,2,3);
$arr2 = array(1,3,4,5);

check($arr1, $arr2);

function check($arr1, $arr2){
$result = array_intersect($arr1, $arr2);
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.