jeudi 31 décembre 2015

If an 'if' statement is true, add it to the list of true ones, else ignore it

I'm trying to make a matching thing. If the 'if' statement like this

  $name = "how"; // <<<this is an input
if(preg_match(  "/(How|my|brain|works)/i",$name)){
                        $result1= "this is one of the results";
}else{
          $result1= " ";

I'm planing to store the results that if there's an actual match, it would display the first message, it might sometimes be pictures. The problem is how I can make it so that when I later do the match and if it's not true it wouldn't have a blank page. How can I skip over it. If for example I'm doing a list and there's about 5 that match with the input, it would display the 5 input instead of showing 10 list. The list would probably look like this

<ul>
  <li><?php echo $result1 ?></li>
  <li><?php echo $resutl2 ?></li>
  <li><?php echo $match10    // and so on ?></li>
</ul>

How can I make it so that it skips over for example match 9 because it's equal to space or display it because it's not equal to space. The problem is that it would list out all 3 and if match9 is equal to space, it would display space and I want it to skip over those.

Aucun commentaire:

Enregistrer un commentaire