Home > Backend Development > PHP Problem > How to remove specified elements from an array in php

How to remove specified elements from an array in php

王林
Release: 2023-03-05 17:48:02
Original
2328 people have browsed it

In PHP, you can use the foreach statement and unset function to remove specified elements from the array. The specific code is [foreach($array as $k=>$v){if($v=='day '){unset($array[$k])}}].

How to remove specified elements from an array in php

We can use the foreach and unset() functions to delete specific elements in the array.

(Related recommendation: php training)

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

Grammar:

void unset ( mixed $var [, mixed $... ] )
Copy after login

Example:

 // 销毁单个数组元素
 unset ($bar['quux']);
Copy after login

(Recommended tutorial: php video tutorial)

Code implementation:

foreach($array as $k=>$v){
    if($v == 'day'){
        unset($array[$k]):
    }
}
Copy after login

The above is the detailed content of How to remove specified elements from an 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