Skip navigation

inBuckets()One of the biggest nightmares I’ve had to deal with is unpredictable cache keys. Inevitably, someone codes a function that uses its parameters in the key name. In many cases, this is fine. However, when you need to deal with paginated or grouped data in different sizes, things can get messy. To that end, I lean on PHP’s range() function.

Setting up the input for range() and making the output usable is something I’ve ended up doing over and over again, so I’m finally taking an implementation sharing it to save everyone the labor of dealing with it (including myself). And thus, I submit inBuckets() for your perusal (hosted at GitHub – sadly wordpress.com won’t let us embed Gists). The syntax is in the doc block and there’s commented out sample code at the end to get you started. Enjoy.

Leave a comment