3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $datasets = array( // less than 10 entries array('127.0.0.1'=>45, '10.0.0.9'=>32, '172.16.0.4'=>'16'), // more than 10 entries array( '10.0.0.1'=>45, '10.0.0.2'=>44, '10.0.0.3'=>43, '10.0.0.4'=>42, '10.0.0.5'=>41, '10.0.0.6'=>40, '10.0.0.7'=>39, '10.0.0.8'=>38, '10.0.0.9'=>37, '10.0.0.10'=>36, '10.0.0.11'=>35, '10.0.0.12'=>34, '10.0.0.13'=>33, '10.0.0.14'=>32, '10.0.0.15'=>31, '10.0.0.16'=>30 ) ); foreach ($datasets as $all_ips) { arsort($all_ips); $top10 = array_slice($all_ips, 0, 10); var_export($top10); echo "\r\n-----\r\n"; }
based on Z0ape
Output for 5.3.21 - 7.2.0
array ( '127.0.0.1' => 45, '10.0.0.9' => 32, '172.16.0.4' => '16', ) ----- array ( '10.0.0.1' => 45, '10.0.0.2' => 44, '10.0.0.3' => 43, '10.0.0.4' => 42, '10.0.0.5' => 41, '10.0.0.6' => 40, '10.0.0.7' => 39, '10.0.0.8' => 38, '10.0.0.9' => 37, '10.0.0.10' => 36, ) -----