Home >Backend Development >PHP Problem >How to delete elements in an array in php

How to delete elements in an array in php

王林
王林Original
2020-08-28 15:05:152585browse

How to delete elements in an array in php: You can use the unset() function to delete. The unset() function can destroy a given variable. For example, if we want to delete a single array element, the code is: [unset ($bar['quux']);].

How to delete elements in an array in php

#We can use the unset() function to delete specific elements in the array.

(Recommended tutorial: php video tutorial)

The unset() function is used to destroy the given variable.

Grammar:

void unset ( mixed $var [, mixed $... ] )

(Related recommendations: php training)

Code example:

<?php
// 销毁单个变量
unset ($foo); 
// 销毁单个数组元素
unset ($bar[&#39;quux&#39;]); 
// 销毁一个以上的变量
unset($foo1, $foo2, $foo3);
?>

Example:

foreach($array as $k=>$v){
if($v == &#39;day&#39;){
unset($array[$k]):
}
}

The above is the detailed content of How to delete elements in an array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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