Jump to content

Sorting Multi-dimensional Array


jandrews3

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.