This article describes 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 about how to use php to search for one-dimensional array elements and delete the elements corresponding to the two-dimensional array, see the following example. 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.