回显PHP结果

I have run into a small snag. I have a PHP function that was originally designed to plain echo a 0 or 1 back to an AJAX request. I now wanted to use the same function in PHP, and again check for a 0 or 1, but the issue is that the echo itself is making its way into my return message.

PHP

function getChildren($db, $table){
 $children = $db->prepare("SELECT...");
 if rowCount()>0
   echo 0;
}

New PHP function

    function delete($db, $table){
      $delete = $db->prepare("DELETE...");
      $delete->execute();
      echo json_encode(array("msg"=>"1"));
    }

if (getChildren($db, $table) == 0){
   deleteFunction($db, $table);
}

The result json echo is 0{msg:0}

Should I make two separate functions, one that echoes and one that just returns a variable?

The first function should return 0, not echo 0.