Home > Backend Development > PHP Problem > How to delete specified value in array in php

How to delete specified value in array in php

王林
Release: 2023-03-04 16:24:01
Original
3559 people have browsed it

php method to delete the specified value in the array: first use the array_search() function to find the specified value in the array, if not found, return false; then use the unset() function to destroy the specified array element.

How to delete specified value in array in php

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

(Recommended tutorial: php graphic tutorial)

Syntax:

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

array_search() function searches for a key value in the array. If the specified key value is found in the array, the corresponding key name is returned, otherwise FALSE is returned. If a key value is found more than once in the array, the key name matching the first found key value is returned.

Grammar:

array_search(value,array,strict)
Copy after login

(Video tutorial recommendation: php video tutorial)

Implementation code:

Use array_search () and unset() functions delete specific values ​​in the array

if(($key = array_search('day',$arr))){
unset($arr[$key]);
}
Copy after login

The above is the detailed content of How to delete specified value in 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