如果名称包含PHP,则隐藏表

I'm listing all my tables (that I see in phpMyAdmin) names using HTML.

I would simply like to "hide" (just in the HTML) the ones which contain "XYZ" in the name of the table.

I made an attempt- but I have not been successful.

<?php foreach($tables as $table):?>
    <li <?php if($table['XYZ'] == $theTable):?>class="active"<?php endif;?>>
    <a href="<?php echo site_url('db/'.$theDB."/".$table['table']);?>"><span class="fui-list-small-thumbnails"></span>&nbsp<?php echo $table['table'];?></a>
    </li>
<?php endforeach;?>

Sure it is possible, either include the list item in the HTML source, but hidden...

<?php
foreach($tables as $table) {
    $pos = strpos($table['table'],'XYZ');
    $class = $pos === false ? 'style="display:none"' : '';
    $href = site_url('db/'.$theDB."/".$table['table']);
    echo "<li {$class}><a href=\"{$href}\"><span class=\"fui-list-small-thumbnails\"></span>&nbsp".$table['table']."</a></li>";
}
?>

Or do not even include the list item in the HTML source

<?php
foreach($tables as $table) {
    $pos = strpos($table['table'],'XYZ');
    if ($pos === false) {
        $href = site_url('db/'.$theDB."/".$table['table']);
        echo "<li><a href=\"{$href}\"><span class=\"fui-list-small-thumbnails\"></span>&nbsp".$table['table']."</a></li>";
    }
}
?>

Key function to test if a string contains another string is strpos. Also I have refactored your code so there is less switching between "view" and "controller" (where view is the HTML being echoed out and the controller is the logic) as this makes code much more readable.

<?php foreach($tables as $table):?>
            <li <?= (($table['XYZ'] == $theTable) ? 'style="display:none"' : "");?>
                <a href="<?= site_url('db/'.$theDB."/".$table['table']);?>"><span class="fui-list-small-thumbnails"></span>&nbsp<?php echo $table['table'];?></a>
            </li>
 <?php endforeach;?>

Try to make the entry invisible, but it would be more performant if you

a) filter in the query or

b) filter before printing the HTML

You can simply make the table visibility hidden like this

<li <?php if($table['XYZ'] == "XYZ"):?>style="visibility: hidden;"<?php endif;?>>

or you can change the visibility: hidden; to display:none;

I think you can achieve like this way.

<?php foreach($tables as $table):?>
        $hideTable = "";
      $hideTable = ($table['XYZ'] == $theTable)? "style='display:none'":'';

 <li <?php echo $hideTable;?> >
            <a href="<?php echo site_url('db/'.$theDB."/".$table['table']);?>"><span class="fui-list-small-thumbnails"></span>&nbsp<?php echo $table['table'];?></a>
        </li>
        <?php endforeach;?> 

Try above code may helps you.