aximbigfan Posted December 22, 2008 Share Posted December 22, 2008 Is there any way to determine where a key is added to an array? I need to be able to put some values at the beginning of the array, and some at the end of the array. Thanks Link to comment https://forums.phpfreaks.com/topic/138070-add-to-beginningend-of-array/ Share on other sites More sharing options...
premiso Posted December 22, 2008 Share Posted December 22, 2008 array array_unshift — Prepend one or more elements to the beginning of an array array_push — Push one or more elements onto the end of array Link to comment https://forums.phpfreaks.com/topic/138070-add-to-beginningend-of-array/#findComment-721716 Share on other sites More sharing options...
redarrow Posted December 22, 2008 Share Posted December 22, 2008 array_unshift() and array_push(). <?php $stack = array("orange", "banana"); array_push($stack, "apple", "raspberry"); print_r($stack); ?> <?php $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); ?> Link to comment https://forums.phpfreaks.com/topic/138070-add-to-beginningend-of-array/#findComment-721719 Share on other sites More sharing options...
aximbigfan Posted December 22, 2008 Author Share Posted December 22, 2008 Great! Thanks! Chris Link to comment https://forums.phpfreaks.com/topic/138070-add-to-beginningend-of-array/#findComment-721723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.