The way PHP deletes the element with the specified key in the array is to use the unset() function to delete, such as [unset($data[0]);]. The unset() function can destroy a single variable or a single array element.
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
It is not difficult to remove the element with the specified key name in the array in PHP. It can be completed through the functions provided by PHP.
The unset() function is used to destroy the given variable. This function has no return value. Using the unset() function we can easily delete the specified element from the array.
Example:
<?php // 销毁单个变量 unset ($foo); // 销毁单个数组元素 unset ($bar['quux']); // 销毁一个以上的变量 unset($foo1, $foo2, $foo3); ?>
Delete the element with the specified key name in the array
unset($data[0]); print_r($data); array (“1”=>1,“2”=>1);
Related video tutorial sharing: php video tutorial
The above is the detailed content of How to delete elements with specified keys in an array in php. For more information, please follow other related articles on the PHP Chinese website!