Northern Flame Posted March 25, 2008 Share Posted March 25, 2008 is there a function that deletes a value from an array? so that if i had <?php $array = array('value', 'val', 'random', 'string'); $delete = 'val'; ?> how do i delete val, which is stored in $delete, from the array? Link to comment https://forums.phpfreaks.com/topic/97856-delete-a-value-from-an-array/ Share on other sites More sharing options...
pocobueno1388 Posted March 25, 2008 Share Posted March 25, 2008 Check this site out: http://tech.petegraham.co.uk/2007/03/22/php-remove-values-from-array/ Link to comment https://forums.phpfreaks.com/topic/97856-delete-a-value-from-an-array/#findComment-500708 Share on other sites More sharing options...
Northern Flame Posted March 25, 2008 Author Share Posted March 25, 2008 thanks thats exactly what i was looking for! Link to comment https://forums.phpfreaks.com/topic/97856-delete-a-value-from-an-array/#findComment-500710 Share on other sites More sharing options...
Barand Posted March 25, 2008 Share Posted March 25, 2008 or, if you know the key of the element to remove, use unset() <?php $val = 2; $a = array(1,2,3,4,5); $key = array_search($val,$a); unset ($a[$key]); echo '<pre>', print_r($a, true), '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/97856-delete-a-value-from-an-array/#findComment-500799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.