3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $pageNumber = 1; $pageHeight = 7; $commands = [ "foo" => ["name" => "foo", "desc" => "Foo Desc", "perm" => true], "fuu" => ["name" => "fuu", "desc" => "Fuu Desc", "perm" => false], "bar" => ["name" => "bar", "desc" => "Foo Desc", "perm" => true], ]; ksort($commands, SORT_NATURAL | SORT_FLAG_CASE); $commands = array_chunk($commands, $pageHeight); $pageNumber = (int) min(count($commands), $pageNumber); printf("PageNumber=%d, CountCommands=%d", $pageNumber, count($commands)); foreach($commands[$pageNumber - 1] as $command){ printf("Name=%s, Desc=%s", $command["name"], $command["desc"]); }
Output for 5.6.0 - 7.3.0rc4
PageNumber=1, CountCommands=1Name=bar, Desc=Foo DescName=foo, Desc=Foo DescName=fuu, Desc=Fuu Desc