Re: retrieve top n entries from an associative array



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

  • Re: reading, writing xml and encoding question
    ... It breaks completely on your XML though. ... public override string Add(string array) ... public override string Add(chararray, int offset, int ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: casting PositionNormalColored[] to byte[]
    ... that pncs is just a pointer to the beginning of an array of structures. ... value, int offset, int count)!!! ... premature optimization is not a good thing! ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Bytebuffer to byte array and Object streams
    ... and a threaded client. ... Okay, ... int offset = buffer.arrayOffset; ... System.arraycopy(bufferArray, offset, array, 0, array.length); ...
    (comp.lang.java.programmer)
  • Re: How do I get the address of (&) an object...
    ... Characters in Java are not bytes. ... want to read bytes use a byte array, ... Then use a 256 byte array, not a char array. ... public void read64(bytedata, int offset) { ...
    (comp.lang.java.help)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)