Validate iTunes links
if (empty($video['itunes']) &amp;&amp; !empty($itunecheck) &amp;&amp; $video['itunes'] != "gol") {



If $video['itunes'] is empty, then you already know that it does not equal "gol".  So you could just say 

if (empty($video['itunes']) &amp;&amp; !empty($itunecheck)) {


And you would get the same effect.  

Similarly, we could rewrite the whole thing as 

if (empty($video['itunes'])) {
    //if mysql row $video['itunes'] is empty check the function ituneslink
    $itunecheck = ituneslink($mystrings);
    //ituneslink is a function that searches the itunes library for Movies/Music
    if (empty($itunecheck)) {
        //if ituneslink function is empty trigger the empty string itunesgol and
        $itunesgol = '';
        $smarty-&gt;assign('itunesgol', $itunesgol);
        itunes_add_item('gol', $video['uniq_id']);
        //add in mysql 'gol' that the itunescheck didn't find anything on itunes 
        //search api, this will be useful for future rechecks
    } else {
        //NOW here I check if itunes is empty and itunescheck not empty and row 
        //itunes not 'gol'. If all of them comply it will be added in the database
        itunes_add_item($itunecheck, $video['uniq_id']);
    }
} elseif($video['itunes'] == 'gol') {
    $itunesgol = '';
    $smarty-&gt;assign('itunesgol', $itunesgol);
    //because itunes search api has a limit of 20 req per minute I had to recheck
    //for this string if available because maybe the first search got 403 
    //forbidden because of too many queries
    $itunecheck = ituneslink($mystrings);
    itunes_add_item($itunecheck, $video['uniq_id']);
} else {
    // if row itunes is not 'gol' it means that itunescheck got the itunes link 
    //and successfully added in database
    $itunecheck = $video['itunes'];
}


This gets rid of the redundant if statements, adding to the original blocks instead.  

Or 

if (empty($video['itunes']) || ($video['itunes'] == 'gol')) {
    // if no cached result, or cached as `gol`
    // fetch new results from iTunes
    $itunecheck = ituneslink($mystrings);
    if (empty($itunecheck)) {
        $itunesgol = '';
        $smarty-&gt;assign('itunesgol', $itunesgol);
        itunes_add_item('gol', $video['uniq_id']);
    } else {
        itunes_add_item($itunecheck, $video['uniq_id']);
    }
} else {
    // otherwise use cached result
    $itunecheck = $video['itunes'];
}


This changes the behavior slightly.  It doesn't assume that a second iTunes search will always return results.  Instead, it treats a cached failure the same as no result in cache.  

But if we do that, we can go ahead and just say 

if (empty($video['itunes'])) {
    // if no cached result
    // fetch new results from iTunes
    $itunecheck = ituneslink($mystrings);
    if (empty($itunecheck)) {
        $itunesgol = '';
        $smarty-&gt;assign('itunesgol', $itunesgol);
    } else {
        itunes_add_item($itunecheck, $video['uniq_id']);
    }
} else {
    // otherwise use cached result
    $itunecheck = $video['itunes'];
}


This removes the concept of caching failures.  Instead, we'll just generate a cache miss next time.  

You could also go the other direction and add more complexity such that you sometimes redo a 'gol' and sometimes don't.  Or whatever.  But as things are written, there doesn't seem to be any reason to have two cases with mostly the same behavior.  

It is of course possible that I'm missing something.  You don't include definitions for ituneslink, itunes_add_item, and $smarty-&gt;assign, so there could be special stuff happening there.  Or prior to this code in setting $video['itunes'].  Or after this code that uses $itunesgol or $itunecheck.  But from what I see of this code, this seems to do mostly the same thing as the original.