Zomie Posted November 27, 2006 Share Posted November 27, 2006 I have a an array that uses a timestamp as the key:[code]Array( [1164606003] => Array ( [1] => 123 [2] => 456 [3] => 789 ) [1164604202] => Array ( [1] => 789 [2] => 456 [3] => 123)[/code]I would like to do a replace on the key so it looks like this:[code]Array( [1] => Array ( [1] => 123 [2] => 456 [3] => 789 ) [2] => Array ( [1] => 789 [2] => 456 [3] => 123)[/code]While maintaining its order, the only php functions I have found to replace the key comes with sort, which changes the order of the array.Is there a function I am missing or an easy way to do this? I apoligize I am fairly new to php, most of my background is in ColdFusion. Link to comment https://forums.phpfreaks.com/topic/28600-help-with-php-arrays-and-sorting/ Share on other sites More sharing options...
btherl Posted November 27, 2006 Share Posted November 27, 2006 http://sg.php.net/manual/en/function.array-merge.phpThis will work, providing your array is numerically indexed (that is, as long as those are ints and not strings). BUT, it will re-index starting with 0, not with 1. Do you need it to start at 1 rather than at 0?array_combine() may also be useful. Link to comment https://forums.phpfreaks.com/topic/28600-help-with-php-arrays-and-sorting/#findComment-130849 Share on other sites More sharing options...
Zomie Posted November 27, 2006 Author Share Posted November 27, 2006 THAT WORKED, I just spent the last 9 hours trying to figure that damn thing out.Grrr thanks alot for the help! Link to comment https://forums.phpfreaks.com/topic/28600-help-with-php-arrays-and-sorting/#findComment-130856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.