Skip to content

Instantly share code, notes, and snippets.

@jtarleton
Created February 18, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtarleton/3210f323b9a428f60162 to your computer and use it in GitHub Desktop.
Save jtarleton/3210f323b9a428f60162 to your computer and use it in GitHub Desktop.
Helper function for array slicing
<?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