Created
December 22, 2010 14:08
-
-
Save o/751548 to your computer and use it in GitHub Desktop.
Sample of using PHP SPL Limit Iterator, you can use for the limiting cached objects
This file contains 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 | |
/** | |
* Creating dummy data for pagination | |
*/ | |
$result = array(); | |
for ($i = 0; $i < 100; $i++) { | |
$result[$i]['age'] = rand(18, 50); | |
$result[$i]['facebook_id'] = rand(1000000, 9999999); | |
} | |
/** | |
* Defining limit and offset | |
*/ | |
$limit = 10; | |
$page = 5; | |
/** | |
* We will use Limit Iterator for filtering data | |
*/ | |
foreach (new LimitIterator(new ArrayIterator($result), $page * $limit, $limit) as $key => $value) { | |
var_dump($key, $value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment