开发者

php, how to sort arrays? [closed]

开发者 https://www.devze.com 2023-04-12 18:00 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

i have this example:

while (...){
echo "test:'.$a.',- group:'.$m.'
}

this will give me something like:

test:name2 - group:7
test:name3 - group:10
test:name4 - group:3
...

how do i display these results ordered by group, ex:

test:name2 - group:10
test:name3 - group:7
test:name4 - group:3
...

any ideas? i believe i can use something like sort() or array_sort, bu t i don't know exactly

thanks.

edit: $a and m are arrays with the values echoed out.

edit2:

i see开发者_运维问答 that many people don't understand my question, well it is very simple to understand. Also i found my answer and here it is:

$HAy[]=array('a' => $a, 'm' => $m);
foreach($HAy as $c=>$key) {
$sort_num_rec[] = $key['a'];
}
array_multisort($sort_num_rec, SORT_DESC, $HAy);
foreach ($HAy as $ay){
//do something
}

was a bit confuse in the beginning, but i figure it out using array_multisort.


You want to sort multiple arrays based on one of the array's sorting order. use array_multisort();

http://www.php.net/manual/en/function.array-multisort.php

array_multisort($m, $a);

this will sort both arrays according to the first arrays sort ordering.

0

精彩评论

暂无评论...
验证码 换一张
取 消