How to delete values ​​in a two-dimensional array in php

王林
Release: 2023-03-07 13:26:02
Original
2809 people have browsed it

php method to delete values ​​in a two-dimensional array: you can use the foreach statement combined with the unset function to delete, such as [foreach($array as $key=>$value){if($key== 'a')[unset($array[$key]);]}].

How to delete values ​​in a two-dimensional array in php

The unset() function is used to clear and destroy variables. For unused variables, we can use unset() to destroy elements.

(Learning video recommendation: java video tutorial)

The same principle as deleting a one-dimensional array, you can delete the corresponding element through the key name of the array.

Example:

array('a1','a2'),'b'=>array('b1','b2'));
foreach($array as $key=>$value){
if($key == 'a')[
unset($array[$key]);
}
//或者删除二维数组中二维中的元素
if($key == 'a')[
unset($array[$key][0]);
}
}
print_r($array);
?>
Copy after login

Related recommendations:php training

The above is the detailed content of How to delete values ​​in a two-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!