The deleted array has repeated values.

Source: Internet
Author: User
If you delete an array, the original array a & nbsp; contains the Value & nbsp; $ a = array (a, B, c); compare array B & nbsp; & nbsp; has the value & nbsp; $ B = array (B); for comparison, we can get $ c = & nbsp; array (a, c); Excuse me, how can I delete an array with repeated values?
The value $ a = array (a, B, c) in the original array );
Compare the values of $ B = array (B) in array B );

Get $ c = array (a, c );

How can I do this.
------ Solution --------------------
Loop judgment or removal
------ Solution --------------------
Use array_diff ($ array_a, $ array_ B)
------ Solution --------------------
Array_diff, Array subtraction
------ Solution --------------------
$a = array(a,b,c);
$b = array(b);
print_r(array_diff($a, $b));
Array
(
[0] =>
[2] => c
)

------ Solution --------------------
Reference:
Use array_diff ($ array_a, $ array_ B)
'
------ Solution --------------------
Http://baike.baidu.com/view/4067743.htm
------ Solution --------------------
In fact, you mean to find the difference set of the two arrays. the system function array_diff () is enough.
------ Solution --------------------
The array_diff () manual contains

------ Solution --------------------
Reference:
Use array_diff ($ array_a, $ array_ B)


$ C = array_diff ($ a, $ B );
Echo "c = {";
Foreach ($ c as $ key => $ value)
{
Echo $ value .",";
}
Echo "}
\ N ";
------ Solution --------------------
Reference:
Use array_diff ($ array_a, $ array_ B)

Take a look at the manual functions.

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.