Declare it then change it, if necessary.

August 16, 2008 · Posted in PHP · Comment 

I recently stumbled then read some PHP optimization tips and realized that this simple bit of code was inefficient.

if (!empty($rec['link_url'])) {
$title= $rec['link_title'];
$url= $rec['link_url'];
} else { $url = ''; }

It’s faster to do this..

$url = '';
$title = $rec['link_title'];
if (!empty($rec['link_url'])) {
$url = $rec['link_url'];
}

You know who you are. Class dismissed.