The example of this article tells the php implementation of searching for the one-dimensional array elements and deleting them Method for corresponding elements of a two-dimensional array. Share it with everyone for your reference. The details are as follows:
Define a one-dimensional array and a two-dimensional array as follows
$fruit=array('apple','orange'); $products = array( array('name'=>'apple','price'=>23.4), array('name'=>'orange','price'=>45.3), array('name'=>'biscuit','number'=>5,'price'=>34) );
You need to find out whether the elements in the $products array intersect with the $fruit elements in the array. If so, keep them, otherwise delete them.
The implementation method is:
foreach($products as $key=>$value) { if(!in_array($value["name"],$fruit)) unset($products[$key]); } array_values($products); //使用unset()销毁数组元素时候应注意索引问题最好使用array_values()给数组重新排序
I hope this article will be helpful to everyone’s PHP programming design.