Introduction
The purpose of a collection is to store objects in an organized manner with specific access rules. We are going to build a collection class using the Standard PHP Library (SPL). Our final product will be capable of iterating, counting and access to objects via array. If you are not familiar with SPL you can [...]
Archives for PHP
Building an Object Collection Manager with the Standard PHP Library (SPL)
Forcing files to download from Amazon S3
I have been messing around with Amazon S3 for hosting files the last few days. One of the things I wanted to do was force a file to download instead of the browser attempting to open it (jpgs, txt, mp3, etc.). A quick Google search didn’t return anything useful. There is a whole bunch of [...]
How we cache at CollegeHumor
CollegeHumor, like many websites that want to reduce database requests and speed up processing, uses memcached as a caching layer. This article will explain our software implementation and discuss a number of things we learned along the way. If you read my blog you will know I’m a PHP guy. CollegeHumor is also coded in [...]
PHP Recursive Multidimensional Array Flatten Using SPL
function array_flatten_recursive($array) {
if($array) {
$flat = array();
foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST) as $key=>$value) {
if(!is_array($value)) {
$flat[] = $value;
}
}
return $flat;
} else {
[...]
Recursive PHP in_array function
I needed a recursive in_array function the other day and disliked all the samples I found on php.net. I wrote this one using the StandardPHPLibrary. It will recursively search through a multidimensional array and return true if the $needle is found in the $haystack.
function in_array_recursive($needle, $haystack) {
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($haystack));
foreach($it [...]
Posts