Skip to content

Instantly share code, notes, and snippets.

@uppfinnarjohnny
Created December 17, 2009 16:02
Show Gist options
  • Save uppfinnarjohnny/258836 to your computer and use it in GitHub Desktop.
Save uppfinnarjohnny/258836 to your computer and use it in GitHub Desktop.
split_chunks
<?php
function split_chunks($input) {
$offset = 0;
foreach(array_slice(func_get_args(), 1) as $length) {
$out[] = substr($input, $offset, $length);
$offset += $length;
}
return $out;
}
$string = 1234567890;
print_r(split_chunks($string, 1, 2, 4, 3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment