NeilTQ Posted February 10, 2010 Share Posted February 10, 2010 Hi Folks. Apologies, but I'm pretty much a complete PHP newb which is why I'm really struggling with this problem that I've got. I had a requirement to transpose an array that I've created and so, through some research, I found this great bit of code (sourced from http://stackoverflow.com/questions/797251/transposing-multidimensional-arrays-in-php) public function flipDiagonally($arr) { $out = array(); foreach ($arr as $key => $subarr) { foreach ($subarr as $subkey => $subvalue) { $out[$subkey][$key] = $subvalue;; } } return $out; } This does almost exactly what I want, except that instead of writing all of the transposed records to a single array, it writes them to what seems to be a collection of arrays within the same object. I've played around with the code a bit but I can't work out how to write those arrays in to a single array within the loop. Can anyone offer any suggestions? Thanks for reading! Link to comment https://forums.phpfreaks.com/topic/191582-array-transpose/ Share on other sites More sharing options...
teamatomic Posted February 10, 2010 Share Posted February 10, 2010 Is it flat or a multi array? HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/191582-array-transpose/#findComment-1009922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.