Re: retrieve top n entries from an associative array



Thanks for the replies. But both programs only meaningful for the
indexed array, not associative array.

I have no idea how to retrieve associative array according to the
length. Can you explain it?

--
Myron Turner wrote:
array array_slice ( array array, int offset [, int length])

<?php
$top_ten = array_slice ( $sorted, 0 , 10);

$a= array (1,2,3,4,5,6,7,8,9,10,11,12);
$top_ten = array_slice ( $a, 0, 10);
print_r ($top_ten);
?>

/* Result:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
)
*/


duzhidian@xxxxxxxxx wrote:
Hello,

After sorting an associative array by value, how can I retrieve top n
entries from it?

Thanks.

Zhidian Du



--

_____________________
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

.



Relevant Pages