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 the array index is not rebuilt.
After checking the information, it turns out that PHP provides this function, but it is very indirect.
This function is array_splice.
For the convenience of use, I encapsulated it into a function for everyone to use.
Copy 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, we can know that the element at position 2 is actually deleted and the index is re-established.
http://www.bkjia.com/PHPjc/323003.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323003.htmlTechArticleCopy the 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...