Home>Article>Backend Development> How to remove two values from an array in php

How to remove two values from an array in php

青灯夜游
青灯夜游 Original
2022-05-09 21:17:43 1767browse

Two removal methods: 1. Call the unset() function twice to delete two elements respectively, the syntax is "unset(array name [subscript/key name])"; 2. Use the array_splice() function Delete two elements from the specified position in the array, the syntax is "array_splice($arr, starting position, 2)".

How to remove two values ​​from an array in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php removes the array two Two methods for a value

Method 1: Call the unset() function twice to delete two elements

The unset() function can Delete a specified element

Syntax:

unset(数组名[下标]); //删除索引数组中的一个元素 unset(数组名["键名"]); //关联数组中的一个元素

Example 1:

How to remove two values ​​from an array in php

Example 2:

"red","b"=>"green","c"=>"blue","d"=>"blue"); var_dump($arr); unset($arr["b"]); unset($arr["d"]); var_dump($arr); ?>

1-How to remove two values ​​from an array in php

Method 2: Use the array_splice() function

When the array_splice() function deletes some elements of the array, it will form these deleted elements into a new one. array.

Example 1: Delete 2 elements from the array from the beginning

How to remove two values ​​from an array in php

Example 2: Delete 2 elements from the array after the 1st element

How to remove two values ​​from an array in php

Example 3: Delete 2 elements from the array after the 2nd element

How to remove two values ​​from an array in php

Recommended learning:《PHP video tutorial

The above is the detailed content of How to remove two values from an array in php. For more information, please follow other related articles on the PHP Chinese website!

php
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