how to remove element from array by key using php

php remove element from array by key

one can remove a specific element from a PHP array by key, following code show how one can unset an array element

Example

Example

you can also remove array element using array_splice , array_splice() function removes selected elements from an array

array_splice(array,start,length)

array_splice uses 3 argument to remove array element

1 – array Specifies an array like $arr
2 – start Numeric value. Specifies which element key require to remove, 0 = first element
3 – length Numeric value. Specifies how many elements will be removed , like 1 only one element need to remove

Leave a Reply

Your email address will not be published. Required fields are marked *