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

How to remove a value from an array in php

王林
Release: 2023-03-04 12:36:02
Original
2534 people have browsed it

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 )
Copy after login

Example:

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

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);
?>
Copy after login

Output result:

Array (
    [0] => a    
    [2] => c
)
Copy after login

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!

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