ashton321 Posted November 24, 2009 Share Posted November 24, 2009 Hi, I have to arrays I would like to make the values of the first become the keys of the new array and the values of the second become the values of the new. I have Array ( [0] => 9 ) Array ( [0] => 15 ) I would like Array( [9] => 15 Or is it possible to loop through two arrays in a foreach at the same time so like both index 0 can be accessed? Quote Link to comment https://forums.phpfreaks.com/topic/182842-combining-the-values-of-two-arrays/ Share on other sites More sharing options...
Alex Posted November 24, 2009 Share Posted November 24, 2009 Use array_combine: $arr1 = Array('key1', 'key2'); $arr2 = Array('val1', 'val2'); $new = array_combine($arr1, $arr2); print_r($new); Quote Link to comment https://forums.phpfreaks.com/topic/182842-combining-the-values-of-two-arrays/#findComment-965050 Share on other sites More sharing options...
ashton321 Posted November 25, 2009 Author Share Posted November 25, 2009 Worked beautifully thank you! Quote Link to comment https://forums.phpfreaks.com/topic/182842-combining-the-values-of-two-arrays/#findComment-965502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.