Simplify your business
Tuesday, 7 October 2008 1:04 pm

The most useful PHP function?

Wednesday, 4 July 2007  

I know that PHP has a lot of functions built right in, some of which are used frequently and some sparingly. But what about “home made” functions that we’ve created? Which are the most used?

I tend to use dd() an awful lot. It’s a simple wrapper for print_r() and I’ve found it very useful for outputting variables directly into the HTML source, so the output it generates is invisible unless you “view source” in the browser:

function dd($var, $cap = 'var') {
   echo "<!-- $cap = ";
   print_r($var);
   echo " -->\n";
}

By removing the HTML comment markers (”<!--” and “-->“) from the above, it’s easily adaptable to PHP CLI as well.

Posted in PHP, Programming by Ivan
Blinklist icon Del.iocio.us icon Furl icon Reddit icon Technorati icon Yahoo! icon

Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.