How to remove an array element in a foreach loop?
Use unset() function to remove array elements in a foreach loop. The unset() function is an inbuilt function in PHP which is used to unset a specified variable. The behavior of this function depends on different things. If the function is called from inside of any user defined function then it unsets the value associated with the variables inside it, leaving the value which is initialized outside it.
unset( $variable )
Return Value: This function does not returns any value.
Below examples use unset() function to remove an array element in foreach loop.
Array (  => GeeksForGeeks_1  => GeeksForGeeks_2  => GeeksForGeeks_3 ) Array (  => GeeksForGeeks_1  => GeeksForGeeks_2 )
Array (  => Array (  => 1 )  => Array (  => 10 )  => Array (  => 100 ) ) Array (  => Array (  => 1 )  => Array (  => 10 ) )
My Personal Notes arrow_drop_up
Please Login to comment...