tastro Posted October 26, 2010 Share Posted October 26, 2010 also i want to change this array: $a=array('a','b','c','d','e','f','g'); to this: $a=array('a','b','c'); i found out that i can unset the last ones, but is there an other way to do that? faster? Link to comment https://forums.phpfreaks.com/topic/216863-how-to-delete-the-last-4-entrys-in-an-array/ Share on other sites More sharing options...
tastro Posted October 26, 2010 Author Share Posted October 26, 2010 found it! for ($x=0; $x<3; $x++) { $b[$x]=$a[$x]; } Link to comment https://forums.phpfreaks.com/topic/216863-how-to-delete-the-last-4-entrys-in-an-array/#findComment-1126597 Share on other sites More sharing options...
litebearer Posted October 26, 2010 Share Posted October 26, 2010 http://www.php.net/manual/en/function.array-slice.php Link to comment https://forums.phpfreaks.com/topic/216863-how-to-delete-the-last-4-entrys-in-an-array/#findComment-1126602 Share on other sites More sharing options...
tastro Posted October 26, 2010 Author Share Posted October 26, 2010 tnx litebear this should work better i think, more efficient. $a=array('a','b','c','d','e','f','g'); $b = (array_slice($a, 0, 3); Link to comment https://forums.phpfreaks.com/topic/216863-how-to-delete-the-last-4-entrys-in-an-array/#findComment-1126638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.