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'=>30, '10.0.0.2'=>31, '10.0.0.3'=>32, '10.0.0.4'=>33, '10.0.0.5'=>34, '10.0.0.6'=>35, '10.0.0.7'=>36, '10.0.0.8'=>37, '10.0.0.9'=>40, '10.0.0.10'=>41, '10.0.0.11'=>42, '10.0.0.12'=>43, '10.0.0.13'=>50, '10.0.0.14'=>51, '10.0.0.15'=>52, '10.0.0.16'=>53 ) ); 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 VfLcP
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.16' => 53, '10.0.0.15' => 52, '10.0.0.14' => 51, '10.0.0.13' => 50, '10.0.0.12' => 43, '10.0.0.11' => 42, '10.0.0.10' => 41, '10.0.0.9' => 40, '10.0.0.8' => 37, '10.0.0.7' => 36, ) -----