"purple","b"=>"orange");array_splice($ a,0,2,$a2);]."/> "purple","b"=>"orange");array_splice($ a,0,2,$a2);].">
Home >Backend Development >PHP Problem >How to delete an array element in php
php method to delete an array element: You can delete an element in the array by using the array_splice function, such as [$a=array("a"=>"purple","b"=> "orange");array_splice($a,0,2,$a2);].
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
Function introduction:
array_splice() function removes the selected element from the array and replaces it with a new element. The function will also return an array of removed elements.
Grammar:
array_splice(array,start,length,array)
Example:
<?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); ?>
Related recommendations: php tutorial
The above is the detailed content of How to delete an array element in php. For more information, please follow other related articles on the PHP Chinese website!