Dale_G Posted November 20, 2008 Share Posted November 20, 2008 hey, i was wondering if its possible to delete an item from an array? $maybe = array( 'xx', 'xxx', 'x', 'abc', 'xxxxxx' ); How could I remove "abc" ($maybe[3]) from the array entirely so that the array would now look something like this: $maybe = array( 'xx', 'xxx', 'x', 'xxxxxx' ); Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/ Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 unset($maybe[3]) Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694788 Share on other sites More sharing options...
flyhoney Posted November 20, 2008 Share Posted November 20, 2008 unset($maybe[3]); Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694789 Share on other sites More sharing options...
Dale_G Posted November 21, 2008 Author Share Posted November 21, 2008 Oops, I meant like where everything shifts over afterwards, so its as if it was never there and $maybe[3] could still be called, it would just be "xxxxxx" now. Basically, delete one item from an array, and shift everything over so all the keys are preserved. Sorry! Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694790 Share on other sites More sharing options...
Dale_G Posted November 21, 2008 Author Share Posted November 21, 2008 *double post* Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694819 Share on other sites More sharing options...
trq Posted November 21, 2008 Share Posted November 21, 2008 array_splice($maybe,3,1) Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694824 Share on other sites More sharing options...
Dale_G Posted November 21, 2008 Author Share Posted November 21, 2008 You got it! Link to comment https://forums.phpfreaks.com/topic/133573-solved-deleting-an-item-from-an-array/#findComment-694826 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.