如果存在demo swicher脚本则设置

i have a demo swicher script. and demo details write in arry like this:

array ("id" => "آکادو",
   "link" => "acadu",
   "url" => "http://demo.domain.ir/template/jm-news-3/",
   "preview" => "http://localhost/demo/fbar//screen/flayz.jpg",
   "j2" => "joomla2.5",
   "j2_color" => "8351a8",
    "j3" => "joomla3",
   "j3_color" => "c29413",
   "ddn" => "http://themeforest.net/user/designingmedia/portfolio?ref=designingmedia"
  )

in body j2 & j3 elemans call in the 2 span tag as blow code:

<?php
                foreach ($theme_array as $i => $theme) :
                echo '<li class="button_a">
                <a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' .
                   $_SESSION['currentthemename']= ucfirst($theme['id']) .' <span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span><span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span></a>';
                    if(isset($theme['preview'])){
                    echo '<img alt="" class="preview" src="';
                    if(strpos($theme['preview'], 'http://') === false){
                    echo 'product_previews/'.$theme['preview'];
                    }
                    else echo $theme['preview'];
                    echo '">';
                    $_SESSION['currentthemename'] =$theme['url'];
                    $current_theme=$_SESSION['currentthemename'];
                    }
                    echo '</li>';
                    endforeach;
                ?>

when one of our demos have both of them we are not any problem. but when one of my demos have one of this elemans j2 or j3 , other eleman with no contet is to be displayed but we do not want to be displayed. we need change this code when one of this eleman in a demo is empty that span tag, It completly not be displayed

you can change:

echo '<li class="button_a">
            <a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' .
               $_SESSION['currentthemename']= ucfirst($theme['id']) .' <span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span><span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span></a>';

to

echo '<li class="button_a"> <a href="#" rel="' . $theme['url'] . ',' . $theme['ddn'] . ','.$theme['link'].'">' . $_SESSION['currentthemename']= ucfirst($theme['id']) .' '.(($theme['j2']=='any-text')?'<span style="background:#'.$theme['j2_color'].'">'.$theme['j2'].'</span>':"").' '.(($theme['j3']=='any-text2')?'<span style="background:#'.$theme['j3_color'].'">'.$theme['j3'].'</span>':"").' </a>';