daily minutia on Twitter

I'm Ingrid Alongi, a developer in Boulder, Colorado. I'm a co-founder at Quick Left, a Web Engineering company. I used to be a software engineer at Gnip where API integration and social media data were my world. Prior to that, at OneRiot, I wrote web applications using Java/Wicket/CSS. I've got experience with CodeIgniter for PHP, but mostly use Zend with Doctrine when it comes to PHP. Got some JQuery too.

I've been in the web development/interactive agency world for almost 10 years, with most of my experience in building database-driven web applications (PHP, ColdFusion) for consumer facing clients (e-commerce, email marketing, advertising, cms, etc.). Lots of strategy, lots of driving traffic back the web site types of stuff. Oh, and managing an amazing team of developers.

I'm an electronic music snob, ex national level cyclist, I play violin and cello, and have an MA in Women's Studies. You can contact me at ialongi at yahoo . com. Or, mosey on over to the Quick Left blog to see what I'm up to.

Recursion in PHP

December 7, 2008, 2:21pm by electromute

Well, I’ve been a bad blogger lately, lots of awesome stuff going in in the world of Ingrid. I’m now working at Gnip. I’ve gotten the chance to do some really cool stuff there, having a great time for sure!

In any case, here’s a little snippet of something I wrote. In Computer Science, recursion is a major conceptual hurdle to get through. Once you master it in school, you sadly may or may not ever see it again. Well, I was fortunate enough to need the beauty of recursion recently.

Say you are trying to calculate the date of the first Sunday in September of 2008. You know that the first day of September is September 1st. The following recursive function in PHP will take the parameters and return the day part of the date. For instance,

// find the first Sunday in September of 2008
// Note that the day of the week in PHP for Sunday is 0.

echo addDay(“9″, “1″, “2008″, “0″);

This will return 7; the first Sunday in September of 2008 is, indeed, September 7, 2008. Here is the function:

function addDay($m, $d, $y, $dbase){
   $tmpDate = mktime(0, 0, 0, $m, $d, $y);
   if (date(“w”, $tmpDate) != $dbase){
     return addDay($m, $d + 1, $y, $dbase);
   } else {
     return $d;
   }
}

Tags: ,

   Read More »