Php searches for one-dimensional array elements and deletes the corresponding elements of the two-dimensional array

Source: Internet
Author: User
Tags array definition
This article mainly introduces how php can search for and delete elements of a one-dimensional array. It involves php's operations on Array definition, traversal, and deletion. For more information, see

This article mainly introduces how php can search for and delete elements of a one-dimensional array. It involves php's operations on Array definition, traversal, and deletion. For more information, see

This example describes how php can search for and delete elements in a one-dimensional array. Share it with you for your reference. The details are as follows:

Define a one-dimensional array. A two-dimensional array is as follows:

$ Fruit = array ('apple', 'Orange '); $ products = array ('name' => 'apple', 'price' => 23.4 ), array ('name' => 'Orange ', 'price' => 45.3), array ('name' => 'biscuit', 'number' => 5, 'price' => 34 ));

You need to find out from the $ products array whether the element has an intersection with the $ fruit element. If yes, keep it; otherwise, delete it.

Implementation Method:

Foreach ($ products as $ key => $ value) {if (! In_array ($ value ["name"], $ fruit) unset ($ products [$ key]);} array_values ($ products); // use unset () when destroying array elements, it is best to use array_values () to re-sort the array.

I hope this article will help you with php programming.

,

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.