Php 从调用的函数返回值

Php 从调用的函数返回值,php,Php,在以下自定义函数中 function get_txtlocal_balance() { $username = variable_get('sms_txtlocal_email'); $hash = variable_get('sms_txtlocal_password'); $data = array('username' => $username, 'hash' => $hash); $ch = curl_init('http://api.txtl

在以下自定义函数中

function get_txtlocal_balance() {
    $username = variable_get('sms_txtlocal_email');
    $hash = variable_get('sms_txtlocal_password');
    $data = array('username' => $username, 'hash' => $hash);
    $ch = curl_init('http://api.txtlocal.com/balance/');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
    $balance = json_decode($response, true);
    echo $balance['balance']['sms'];
}
我从本地账户返回余额。现在,我试着将这种平衡呼应到位

$balance = get_txtlocal_balance();
$title = 'SMS Integration - Current Balance: ' . $balance;

<span><?php echo $title;?></span>
$balance=get_txtlocal_balance();
$title='SMS集成-当前余额:'$平衡;
但是返回的值没有出现在正确的位置,它总是返回在页面的顶部,有人能发现我做错了什么吗?

替换以下代码:

function get_txtlocal_balance() {
$username = variable_get('sms_txtlocal_email');
$hash = variable_get('sms_txtlocal_password');
$data = array('username' => $username, 'hash' => $hash);
$ch = curl_init('http://api.txtlocal.com/balance/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$balance = json_decode($response, true);
return $balance['balance']['sms'];
}

返回$balance['balance']['sms']啊,上帝。哈哈。谢谢如果你愿意的话,可以贴出来作为回答?@u_mulder你真谦虚;-)