Thursday, January 1, 2009

How to remove an element from an array variable in php

php unset() will not only unset a single variable, you can also remove elements from a array variable using unset(). Look at the following code.
See that the index 2 is not in the array any more and the $my_array is not in the correct index sequence. you can reassign indexes using the array_values()


<?php

$my_array = array('Hello', 'Bye', 'Kusal', 'kuppiya');

unset($my_array[2]); // remove kusal from array

print_r($my_array);

/*
Result:

Array ( [0] => Hello [1] => Bye [3] => kuppiya )

*/
?>


Get custom programming done at GetAFreelancer.com!

No comments:

Post a Comment