How to delete a certain field in a two-dimensional array in php: first create a PHP sample file; then use the array_walk and array_diff functions to delete a certain field in the array.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php How to delete a field in a two-dimensional array?
The two functions array_walk and array_diff are mainly used here.
Example:
$list = [ 0 => [ 'id' => 1001, 'name' => '张三', 'sex' => '男' ], 1 => [ 'id' => 2091, 'name' => '李四', 'sex' => '女' ] ];
Assuming that you need to remove the name sex column in the above array, you can directly:
array_walk($list, function (&$item) { $item = array_diff($item, ['name', 'sex']); });
Recommended learning: "PHP Video Tutorial 》
The above is the detailed content of How to delete a field in a two-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!