函数返回数组而不是值

时间:2013-08-11 17:18:23

标签: php arrays

我在PHP中有一个函数返回数组而不是值 你能告诉我我做错了吗

function get_current_call_count() {
    //Variable declearation
    $line1="";
    $line2="";
    $total_call_count="";
    $current_call_count="";
    $var=array();
    // Executing shell command to get total number.
    $shell_command = ("/usr/sbin/asterisk -rx 'core show calls'");
    exec($shell_command,$result,$status);
    //print_r($result);
    $line1=explode(" ",$result['0']);
    $current_call_count=$line1['0'];
    $line2=explode(" ",$result['1']);
    $total_call_count=$line2['0'];
    $var=array("$current_call_count","$total_call_count");
    return($var);
    //echo("Current call count is $current_call_count and Total system call count is $total_call_count");
}

1 个答案:

答案 0 :(得分:1)

你的函数正在返回数组,因为你这样做了:

$var=array("$current_call_count","$total_call_count");
return($var);

所以一切都很好。我怀疑稍后您尝试将此函数返回的值用作非数组,因此进行强制转换并以“Array”字符串结束。但是在以后的代码中你的错。如果你想使用数组中的某个值,你必须从那里得到它,这很可能在你的其他代码中丢失了。

相关问题