PHP用户定义的函数,只返回“echo”

时间:2014-01-07 12:09:15

标签: php

奇怪的问题。

我有这段代码:

function createNumber()
{
    // other code initialisizing $base and $arr
    $result = checkArray($base, $arr);
    echo $result; // <- this doesn't print nothing
} // function

function checkArray($value,$array)
{
    $result = '';
    if (in_array($value,$array))
    {
        $value = $value+1;
        checkArray($value,$array);
    }
    else
    {
        $result = $value;
        //return $result;
        //echo $result; <- this doesn't print nothing
    }
    echo $result; // <- this print the right value
    //return $result; // <- this seems doesn't return nothing
}

如果在checkArray我取消注释return $result row并发表评论echo $result,则会正确打印$ result。

否则,似乎不返回任何内容(即createNumber函数不会打印任何内容。

有可能吗?

0 个答案:

没有答案