Jump to content

Sort multi-dimensional array


abdfahim

Recommended Posts

Hi,

 

I have one array like this

$a[0][0] = "aasd";
$a[0][1] = "3";
$a[0][2] = "dsad";

$a[1][0] = "eq";
$a[1][1] = "1";
$a[1][2] = "dsf";

$a[2][0] = "tre";
$a[2][1] = "2";
$a[2][2] = "ete";

etc.

 

Now I want to sort the 1st index of the array based on value of $a[][1]. That means, in each $a[][1] item, I have a number, and I want to sort the 1st index of array based on that number (I dont wanna sort the sub-array). So, after sorting, the array should look like,

 

 


$a[0][0] = "eq";
$a[0][1] = "1";
$a[0][2] = "dsf";

$a[1][0] = "tre";
$a[1][1] = "2";
$a[1][2] = "ete";

$a[2][0] = "aasd";
$a[2][1] = "3";
$a[2][2] = "dsad";

etc.

 

Is there any easy way except manual loop and check?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/201101-sort-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.