-1

値ではなく配列を返す関数が 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");
}
4

1 に答える 1

1

関数は配列を返します。これは、次のようにしたためです。

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

それで、すべて問題ありません。後で、この関数によって返された値を非配列として使用しようとすると、キャストが発生し、「配列」文字列で終了すると思われます。しかし、それは後のコードであなたのせいです。配列から特定の値を使用する場合は、そこから取得する必要がありますが、これは他のコードでは欠落している可能性があります。

于 2013-08-11T17:32:13.967 に答える