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