How to remove values ​​from an array in php

王林
Release: 2023-03-02 19:44:01
Original
2342 people have browsed it

The way PHP removes values ​​from an array is through the array_splice() function. This function removes a selected element from an array and replaces it with a new element. The specific usage method is: [array_splice($a1,0,2,$a2);].

How to remove values ​​from an array in php

array_splice() function removes the selected element from an array and replaces it with a new element. The function will also return an array of removed elements.

(Recommended tutorial: php tutorial)

Function syntax:

array_splice(array,start,length,array)
Copy after login

Code implementation:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"purple","b"=>"orange");
array_splice($a1,0,2,$a2);
print_r($a1);
?>
Copy after login

Print results:

Array ( [0] => purple [1] => orange [c] => blue [d] => yellow )
Copy after login

The above is the detailed content of How to remove values ​​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