Home > Backend Development > PHP Problem > How to delete an array element in php

How to delete an array element in php

PHPz
Release: 2023-03-04 17:48:02
Original
1753 people have browsed it

How to delete an array element in php: You can use the array_splice() function to delete it. The array_splice() function removes a selected element from an array and replaces it with a new element. This function returns the array of removed elements.

How to delete an array element 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 graphic tutorial)

Note: The key names in the replacement array are not retained.

Grammar:

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

(Video tutorial recommendation: php video tutorial)

Example:

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

Output result:

Array ( [a] => red [b] => green )
Copy after login

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!

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