"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

How to delete an array element in php

王林
王林Original
2021-02-20 16:00:572179browse

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);].

How to delete an array element in php

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!

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