w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
foreach statement echo once if nested foreach is empty?

Your logic is backwards. You should start with a "nothing found" condition, and change it to false when something is found:

$not_found = true;

while ...
   if ($search->found_posts != 0) {
     $not_found = false;
if ($not_found) {
  echo 'nothing found'; // $not_found is true
} else {
  echo 'found something'; // $not_found is false

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.