Jump to content

Sorting multidimentional arrays?


rustyofco

Recommended Posts

My array goes like this:
[code]$array[1][a] = 8253EF
$array[1][b] = joe

$array[2][a] = 2016HG
$array[2][b] = bob

$array[3][a] = 5768NT
$array[3][b] = adam[/code]

I want to sort it so that the item in the [a] key goes ascending alphabetically (alphanumerically), but it stays with its associated name (the b key).

So in the end, I want

[code]$array[1][a] = 2016HG
$array[1][b] = bob

$array[2][a] = 5768NT
$array[2][b] = adam

$array[3][a] = 8253EF
$array[3][b] = joe[/code]

What function is this?
Link to comment
https://forums.phpfreaks.com/topic/27618-sorting-multidimentional-arrays/
Share on other sites

In this instance

[code]
<?php
$array[1]['a'] = '8253EF';
$array[1]['b'] = 'joe';

$array[2]['a'] = '2016HG';
$array[2]['b'] = 'bob';

$array[3]['a'] = '5768NT';
$array[3]['b'] = 'adam';

array_multisort($array) ;

echo '<pre>', print_r($array, true), '</pre>';

?>
[/code]

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.