Results Reporting / Checking with Multiple Results in For Loop hoping to be schooled a little bit here in showing "no results".
This is a working snippet, but I'd like to know if there is a more elegant way to show errors when comparing multiple values in an IF statement within a ForLoop... I could have 10 results with only 2 matching my if statement:

if($value["IsArchived"] == false &amp;&amp; !preg_match("/^123 ABC/", $value["ProjectName"]))


Is there better way than capturing a count variable $totalToShow == 0 to show my "No Results" in a new IF statement or is that ok?  

$obj = drupal_json_decode($result);
//used to show NO RECORDS or not... probably a more elegant way here?!
$totalToShow = 0;
//loop through the json data and add it to the $output array.
//NOTE: not checking if any are empty
$output .= '&lt;ul class="list-group" style="margin-bottom:15px;"&gt;';
//check if the obj is empty, if so, no records to display...
if (!empty((array) $obj)) {
  foreach($obj as $key=&gt;$value){
    if($value["IsArchived"] == false &amp;&amp; !preg_match("/^123 ABC/", $value["ProjectName"])){
        $totalToShow++;
        //output project name link to project # and append start/end date after link.
        $output .= '&lt;li class="list-group-item"&gt;&lt;strong&gt;' . $value["ProjectName"] . '&lt;/strong&gt; ('. _abc_date($value["CommentStart"]) . " - " .  _abc_date($value["CommentEnd"]).') ';
        if($lrnmore != ""){
            $output .= ' | &lt;a href="CommentInput?project='.$value["ProjectNumber"].'"&gt;'. $lrnmore .'&lt;/a&gt;';
        } 
        $output .= '| &lt;a href="ReadingRoom?project='.$value["ProjectNumber"].'"&gt;View Comments&lt;/a&gt;&lt;br/&gt;';
        $output .= '&lt;ul&gt;&lt;li&gt;' . $value["Description"] . '&lt;/li&gt;&lt;/ul&gt;';
        $output .= "&lt;/li&gt;";
    }
  }
  if($totalToShow == 0){
    $output .= '&lt;li class="list-group-item"&gt;No Records to Display&lt;/li&gt;';
  }
In case there is any chance to use a template engine, then you should prepare your data first

$obj = drupal_json_decode($result);
$output = [];
foreach($obj as $row){
    if(!$value["IsArchived"] &amp;&amp; !preg_match("/^123 ABC/", $value["ProjectName"])){
        $row['CommentStart'] = _abc_date($value["CommentStart"]);
        $row['CommentEnd'] = _abc_date($value["CommentEnd"]);
        $output[] = $row;
    } 
}


and then output it (an exampe is using Twig template engine but the logic would be the same even with raw PHP)

{% for value in output %}
    &lt;li class="list-group-item"&gt;
        &lt;strong&gt;{{ value["ProjectName"]}}&lt;/strong&gt;
        ({{ value["CommentStart"] }} - {{ value["CommentEnd"] }})
        {% if lrnmore %}
            | &lt;a href="CommentInput?project= {{ value["ProjectNumber"] }}"&gt;
                 {{ lrnmore }}
              &lt;/a&gt;
        {% endif %} 
        | &lt;a href="ReadingRoom?project={{ value["ProjectNumber"] }}"&gt;
            View Comments
        &lt;/a&gt;&lt;br/&gt;
        &lt;ul&gt;&lt;li&gt; {{ value["Description"] }}&lt;/li&gt;&lt;/ul&gt;
    &lt;/li&gt;
{% endfor %}
{% if not output %}
    &lt;li class="list-group-item"&gt;No Records to Display&lt;/li&gt;
{% endif %}


this way you will have a clear separation between the business logic and display logic and as a bonus you will have HTML which is readable and maintainable.