PHP implements a method of searching one-dimensional array elements and removing the corresponding elements of a two-dimensional array, dimension two-dimensional array _php tutorial

Source: Internet
Author: User

PHP implements a method of searching one-dimensional array elements and removing the corresponding elements of a two-dimensional array, a two-dimensional array of dimensions


In this paper, we describe a method that PHP implements to search one-dimensional array elements and delete the corresponding elements of a two-dimensional array. Share to everyone for your reference. Specific as follows:

Define a one-dimensional array with a two-dimensional array 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));

It is necessary to implement a lookup from the $products array whether the elements and arrays of $fruit elements have an intersection, if any, to retain, otherwise delete.

The implementation method is:

foreach ($products as $key = + $value) {   if (!in_array ($value ["name"], $fruit))   unset ($products [$key]);} Array_values ($products);//Use unset () to destroy an array element should be aware of the index problem best use array_values () to reorder the array

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1027493.html www.bkjia.com true http://www.bkjia.com/PHPjc/1027493.html techarticle PHP Implementation of the search for one-dimensional array elements and delete the two-dimensional array of corresponding elements of the method, the dimension of two-dimensional array in this paper, the implementation of PHP to search one-dimensional array elements and delete two-dimensional array corresponding elements ...

  • 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.