jandrews3 Posted January 4, 2010 Share Posted January 4, 2010 I'm trying to use the following code to sort a multidimensional array. It sorts the value $data[$count]['name'], but doesn't sort any of the other fields like ['email'], ['address']. Hence, I'm actually getting a display that sorts the order of names but leaves the rest of the data as it was. This obviously creates an inaccurate list. Please please tell me there's a simple fix. $sortarray = array(); foreach($data as $key=>$value) { $sortarray[$value['id']] = $value['name']; } asort($sortarray); $data = array(); $counter = 0; foreach($sortarray as $key=>$value) { $data[$counter]['name'] = $value; $data[$counter]['id'] = $key; $counter++; } Link to comment https://forums.phpfreaks.com/topic/187073-sorting-multi-dimensional-array/ Share on other sites More sharing options...
jandrews3 Posted January 4, 2010 Author Share Posted January 4, 2010 Nevermind. I gots it. Thanks anyhow. Link to comment https://forums.phpfreaks.com/topic/187073-sorting-multi-dimensional-array/#findComment-987896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.