Skip to content

Instantly share code, notes, and snippets.

@kriswallsmith
Last active December 18, 2015 17:29
Show Gist options
  • Save kriswallsmith/5819198 to your computer and use it in GitHub Desktop.
Save kriswallsmith/5819198 to your computer and use it in GitHub Desktop.
How do you walk a paginated API?
<?php
function walk($callback)
{
$page = 1;
do {
$results = fetch($page++, 100);
foreach ($results as $result) {
call_user_func($callback, $result);
}
} while (100 == count($results);
}
function fetch($page, $perPage)
{
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment