从其他函数调用variabel(php)

时间:2017-09-02 07:06:35

标签: php function variables

我有这段代码

class foo
{
    function one()
    {
        $number = 1;
    }

    function two()
    {
        echo $number;
    }

}

我想在function one()上拨打来自function two()的$ number。 是否有可能做到这一点 ?

1 个答案:

答案 0 :(得分:1)

Hello Mfdsix Indo,

试试这段代码,

class foo
{
    function one()
    {
        $number = 1;
        return $number;
    }

    function two()
    {
        echo $this->one();
    }
}

OR

class foo
{
    private $number;
    function one()
    {
        $this->number = 1;
    }

    function two()
    {
        echo $this->number;
    }
}

我希望我的答案有用 如果有任何疑问请评论。

相关问题