Home > Backend Development > PHP Tutorial > How to use the vlookup function PHP method to delete specific array contents and rebuild the array index

How to use the vlookup function PHP method to delete specific array contents and rebuild the array index

WBOY
Release: 2016-07-29 08:44:38
Original
2248 people have browsed it

Copy code The code is as follows:


$a = array('a','b','c','d');
unset($a[2]);
print_r($a );


But the biggest disadvantage of this method is that it does not rebuild the array index.
After checking the information, it turns out that PHP provides this function. It is just very indirect..
This function is array_splice.
For the convenience of use, I encapsulated it It has become a function. It is convenient for everyone to use.

Copy the code The code is as follows:


function array_remove(&$arr,$offset){
array_splice($arr,$offset,1);
}
$ a = array('a','b','c','d');
array_remove($a,2);
print_r($a);


After testing, you can know the position of this element. 2 It was actually deleted. And the index was re-established.

The above introduces how to use the vlookup function. How to delete specific array contents and rebuild the array index in PHP, including how to use the vlookup function. I hope it will be helpful to friends who are interested in PHP tutorials.

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