ryandward Posted May 14, 2011 Share Posted May 14, 2011 I am trying to invert some arrays, making the x-values y, and the y-values x. I have found the code that works, but I cannot understand for the life of me, I have a multidimensional $data array; that looks like this: row:0 :: Country:Algeria row:1 :: Country:USA row:2 :: Country:Morocco The following code successfully extracts the appropriate 'column' from my array. foreach($data as $value){ $invert['country'][] = $value['country']; } It returns: $invert['country'] = Algeria, USA, Morocco But this makes no sense, it seems more logical that the code should be: foreach($data as $value){ $invert[] ['country']= $value['country']; } Since we are accepting all values of the first array, and then specifying the second array. What am I missing here? Why is it working backwards? Link to comment https://forums.phpfreaks.com/topic/236402-unexpected-behavior-foreach-invertcountry-valuecountry/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.