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

How to delete specified value in array in php

王林
王林Original
2020-08-17 14:22:043565browse

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 $... ])

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)

(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]);
}

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!

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