da-vid Posted August 7, 2009 Share Posted August 7, 2009 Alright, so I have this code: $weekvotes = array_merge($weekvotes, array($song['id'] => 1)); And $song['id'] = 14. However, the array comes out as [0] => 1 instead of [14] => 1. ... However, when I do this: $weekvotes = array_merge($weekvotes, array($song['id'] .' ' => 1)); It shows up properly as [14 ] => 1. However, I do not want the space, but when I remove it, it changes back to 0. Link to comment https://forums.phpfreaks.com/topic/169203-solved-using-a-variable-in-an-array/ Share on other sites More sharing options...
da-vid Posted August 7, 2009 Author Share Posted August 7, 2009 Um... okay, I actually solved it right after posting. I changed it to: $testarray = array($song['id'] => 1); $weekvotes = array_merge($weekvotes, $testarray); I don't see why this works and what I did originally does not, though. Link to comment https://forums.phpfreaks.com/topic/169203-solved-using-a-variable-in-an-array/#findComment-892768 Share on other sites More sharing options...
da-vid Posted August 7, 2009 Author Share Posted August 7, 2009 ... k, found yet anther issue. $testarray = array($song['id'] => 1); $weekvotes = array_merge($weekvotes, $testarray); If I print_r($testarray), it shows up fine as [14] => 1, but when I print_r($weekvotes) it comes out again as [0] => 1. >_> Link to comment https://forums.phpfreaks.com/topic/169203-solved-using-a-variable-in-an-array/#findComment-892773 Share on other sites More sharing options...
da-vid Posted August 7, 2009 Author Share Posted August 7, 2009 LOL, and I found the problem again. $weekvotes was just a blank array (array()) but it works once I change it to array('' => ''). Link to comment https://forums.phpfreaks.com/topic/169203-solved-using-a-variable-in-an-array/#findComment-892777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.