Created
February 18, 2015 15:28
-
-
Save jtarleton/3210f323b9a428f60162 to your computer and use it in GitHub Desktop.
Helper function for array slicing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HelperLibrary { | |
// Utility to slice an associative array | |
public static function assoc_array_slice($array, $offset, $count) { | |
$result = array(); | |
$keys = array_keys($array); | |
$end = min($offset + $count, count($array)); | |
for ($i = $offset; $i < $end; $i++) { | |
$result[$keys[$i]] = $array[$keys[$i]]; | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment