Factorials & Recursive Functions
In my ongoing quest to become a hardcore developer, I had an awesome session yesterday with Ben Doherty at Oomph, a web marketing firm here in Boston. Ben helped me wrap my head around recursion -- creating a function that calls itself -- by asking me to write a PHP function that would calculate the factorial of a given number ($n). It took me a few minutes, mainly because I've never studied trigonometry or learned what a factorial was! We were working on a whiteboard, which made it even more difficult...but on my second attempt I got it to work. Then I asked Ben how he would write it and, as an added bonus, he showed me a bit of PHP shorthand that reduced the code to a single line.
Here is the code, with a simple HTML form added so you can actually use it: http://pastebin.com/9436TUYk










