Home  >  Article  >  Backend Development  >  How to remove a value from an array in php

How to remove a value from an array in php

王林
王林Original
2020-08-13 13:53:232502browse

php method to remove a certain value in an array: You can use the unset() function to remove it. The unset() function is used to destroy a given variable, such as [unset ($bar['quux'])], which means destroying a single array element. The unset() function does not change other keys.

How to remove a value from an array in php

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

(Recommended tutorial: php graphic tutorial)

Grammar:

void unset ( mixed $var )

Example:

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

Note: unset() The method does not change other keys.

(Video tutorial recommendation: php video tutorial)

Code implementation:

<?php
    $array = array(0 => "a", 1 => "b", 2 => "c");
    unset($array[1]);
    print_r($array);
?>

Output result:

Array (
    [0] => a    
    [2] => c
)

The above is the detailed content of How to remove a value from 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