bcamp1973 Posted July 14, 2006 Share Posted July 14, 2006 So, i have an array...[code]$arr => ('a','b','c')[/code]...and i want to remove one value from that array before submitting it to a function so it will look like...[code]Array => ('a','c')[/code]Is this possible? I can only find functions to strip the beginning/end off an array, but nothing in between :( Link to comment https://forums.phpfreaks.com/topic/14554-removing-selected-value-from-array/ Share on other sites More sharing options...
pixy Posted July 14, 2006 Share Posted July 14, 2006 I've been wanting to know how to do that too. The only thing I could think of is using serialize and then trying to take it out. But i'm stumped there, too.You can use in_array() to detect it, but not remove. Link to comment https://forums.phpfreaks.com/topic/14554-removing-selected-value-from-array/#findComment-57735 Share on other sites More sharing options...
.josh Posted July 14, 2006 Share Posted July 14, 2006 if you have an array $blah = array('a','b','c');you would access for instance 'b' with $blah[1] since array positions start at zero. so if you wanted to delete 'b' from that array you would do this:unset ($blah[1]); Link to comment https://forums.phpfreaks.com/topic/14554-removing-selected-value-from-array/#findComment-57744 Share on other sites More sharing options...
bcamp1973 Posted July 14, 2006 Author Share Posted July 14, 2006 Perfect! Thanks Caryon Violent...you've saved me more than once on here :) I was imploding the array, stripping the value using str_replace, then exploding it again...exceptionally sloppy I know! Link to comment https://forums.phpfreaks.com/topic/14554-removing-selected-value-from-array/#findComment-57746 Share on other sites More sharing options...
.josh Posted July 14, 2006 Share Posted July 14, 2006 but just so you know, if you do that, even though you will end up with an array of array('a','b') your keys will be (0,2) not (0,1) if you wish for there not to be a gap, then after unsetting 'b', you will want to do this:$blah = array_values($blah);this will re-index your array. Link to comment https://forums.phpfreaks.com/topic/14554-removing-selected-value-from-array/#findComment-57749 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.