Home >Backend Development >PHP Problem >How to remove values from an array in php
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);].
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!