PHP code to delete array and two-dimensional array values

Source: Internet
Author: User

Here's how:

  1. $arr = Array (...);//Suppose there are arrays of 10,000 elements with duplicate elements in them.
  2. $arr = Array_flip (Array_flip ($arr)); This allows you to remove duplicate elements.

What the hell is going on here? Take a look at the role of Array_flip (): Array_flip () is used to exchange the key and value of each element of an array, such as:

  1. $arr 1 = Array ("Age" = +, "name" = "Happy Garden");
  2. $arr 2 = array_flip ($arr 1); $arr 2 is the array ("Age", "happy garden" = "name");

In an array of PHP, allow different elements to take the same value, but not allow the same key name to be used by different elements, such as:

  1. $arr 1 = Array ("Age" = +, "name" = "Happy Garden", "Age" and "age" = 20); "Age" = 20 will replace "age" + 30
  2. $arr 1 = Array ("name" = "Happy Garden", "age" = 45);

Here $arr 1 is equal to $ARR2, so we can see why Array_flip (Array_flip ($arr)) can delete the duplicate elements in the array, first, the value in the $arr becomes the key name, because the value is duplicated, After becoming a key name, these duplicate values become duplicate key names, and the PHP engine deletes the duplicate key names, leaving only the last one. Such as:

  1. $arr 1 = Array ("Age" = +, "name" = "Happy Garden", "Age" and "age" = 20);
  2. $arr 1 = array_flip ($arr 1); $arr 1 becomes an array ("Happy garden" = "name", "Age");
  3. Then the key name and the value of the $arr 1 are also complex:
  4. $arr 1 = array_flip ($arr 1);

The above code is concise: $arr 1 = array_flip (Array_flip ($arr 1));


May 6 can break 3,000 points "beginners knowledge of stocks": http://licai.daiyuline.com/gupiao/359.html

Non-farm night who main oil city ups and downs "international crude oil price": http://licai.daiyuline.com/yyjg/358.html

Non-agricultural express gold What to do tonight "gold price trend": http://licai.daiyuline.com/guijinshu/357.html

PHP code to delete array and two-dimensional array values

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.