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.
|