knowram Posted April 19, 2006 Share Posted April 19, 2006 I know this is a stupid question. But I just can't seem to find that answer. Given an array and a variable is there some way to delete that variable from the array no mater where it is located in that array?I know there must be some easy function for this but I can't seem to find it.thanks for the help. Quote Link to comment Share on other sites More sharing options...
poirot Posted April 19, 2006 Share Posted April 19, 2006 Use unset()[a href=\"http://www.php.net/manual/en/function.unset.php\" target=\"_blank\"]http://www.php.net/manual/en/function.unset.php[/a] Quote Link to comment Share on other sites More sharing options...
knowram Posted April 19, 2006 Author Share Posted April 19, 2006 I did find that but I can't seem to figure out how to use it. This is what i am doing.$x = array (testing, dog, cat, testing2);$newx = unset($x['testing2']);That dose not seem to do anything. Quote Link to comment Share on other sites More sharing options...
poirot Posted April 19, 2006 Share Posted April 19, 2006 [code]$x = array (testing, dog, cat, testing2);print_r($x);$k = array_search('testing2', $x);unset($x[$k]);print_r($x);[/code][code]// The first print_r Array( [0] => testing [1] => dog [2] => cat [3] => testing2)// Second print_rArray( [0] => testing [1] => dog [2] => cat)[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.