如何让函数返回一个json字符串在php中调用它们?

I made the following script but I want that each script should echo the json_encode array only when I call the function. When I tried defining the function, and then calling it, it displayed nothing. It is working if the scripts are not made in the functions. How do I make different functions and then call different functions according to my usage?

<?php

ini_set('display_errors', '0');
error_reporting(0);
require_once("include/db.php");
date_default_timezone_set('Asia/Kolkata');

$regno ='14ASDFJ234';
$password = '0';
$name = 'EASPORTS';
$priority = 0;

//fetch priority
$query = "SELECT priority FROM users WHERE regno='{$regno}' AND pass='{$password}' LIMIT 1";
$res = mysql_query($query, $conn) or die(mysql_error());
$found = mysql_fetch_array($res);

if($found)
{
    $priority=$found['priority'];               
}

//echo $priority;
echo 'news feed : <br> '
$sql = "SELECT  * FROM newsfeed";
$result = mysql_query($sql,$conn) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {

    $details[] = array(
        'name' => $row['name'],
        'feed' => $row['feed']         
    );
}   

echo json_encode($details);

// announcement details...
echo "<br> Announcement details: <br>";

$sql1 = "SELECT  * FROM announcements WHERE name = '$name'";
$result1 = mysql_query($sql1,$conn) or die(mysql_error());

while ($row1 = mysql_fetch_array($result1)) {

    $details1[] = array(
        'name' => $row1['name'],
        'pname' => $row1['pname'],
        'date' => $row1['date'],
        'time' => $row1['time'],
        'status' => $row1['status']       
    );
}   

echo json_encode($details1);

//events script...

?>

You should do like this

public function somefunction()
{
        $query = "SELECT priority FROM users WHERE regno='{$regno}' AND pass='{$password}' LIMIT 1";
    $res = mysql_query($query, $conn) or die(mysql_error());
    $found = mysql_fetch_array($res);
    if($found)
    {
            $priority=$found['priority'];


        }

//echo $priority;
echo 'news feed : <br> '
$sql="SELECT  * FROM newsfeed";
$result=mysql_query($sql,$conn) or die(mysql_error());

while ($row=mysql_fetch_array($result)) {



        $details[] = array(
            'name' => $row['name'],
            'feed' => $row['feed']

        );
        }   
        echo json_encode($details);
}

now when you call somefunction() you will get json encoded array as result