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

How to remove values ​​from an array in php

王林
王林Original
2020-07-21 15:51:262334browse

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)

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);
?>

Print results:

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

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!

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