Home > Article > Backend Development > How to remove a value from an array in php
php method to remove a certain value in an array: You can use the unset() function to remove it. The unset() function is used to destroy a given variable, such as [unset ($bar['quux'])], which means destroying a single array element. The unset() function does not change other keys.
# The unset() function is used to destroy the given variable.
(Recommended tutorial: php graphic tutorial)
Grammar:
void unset ( mixed $var )
Example:
// 销毁单个数组元素 unset ($bar['quux']);
Note: unset() The method does not change other keys.
(Video tutorial recommendation: php video tutorial)
Code implementation:
<?php $array = array(0 => "a", 1 => "b", 2 => "c"); unset($array[1]); print_r($array); ?>
Output result:
Array ( [0] => a [2] => c )
The above is the detailed content of How to remove a value from an array in php. For more information, please follow other related articles on the PHP Chinese website!