charles.ca Posted October 15, 2010 Share Posted October 15, 2010 Hi .. i have an array format like (mysql result array) $new_array=Array ( [0] => Array ( [quantity] => 5 ) [1] => Array ( [quantity] => 25 ) [2] => Array ( [quantity] => 20 ) ) I have to convert this array into the following format $new_array['quantity'][0]=5 $new_array['quantity'][1]=25 $new_array['quantity'][2]=20 How to convert this array format using any standard array method. Quote Link to comment https://forums.phpfreaks.com/topic/215937-how-to-exchange-array-keys/ Share on other sites More sharing options...
Adam Posted October 15, 2010 Share Posted October 15, 2010 There is no standard PHP function to do that. You can use a loop though: $seomthing = array(); foreach ($new_array as $key => $value) { $something['quantity'][$key] = $value['quantity']; } print_r($something); Quote Link to comment https://forums.phpfreaks.com/topic/215937-how-to-exchange-array-keys/#findComment-1122456 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.