0

我有一个在类中的函数,我想要一个函数中的 var。我$this用来从类中的函数调用 var 。但不知道如何使用参数调用函数。我想$post['who']['points']使用外部功能。

功能

function post_meta_who($post, $class)
        {
            if (isset($post['who'])) {
                $this->output('<SPAN CLASS="'.$class.'-who">');

                if (strlen(@$post['who']['prefix']))
                    $this->output('<SPAN CLASS="'.$class.'-who-pad">'.$post['who']['prefix'].'</SPAN>');

                if (isset($post['who']['data']))
                    $this->output('<SPAN CLASS="'.$class.'-who-data">'.$post['who']['data'].'</SPAN>');

                if (isset($post['who']['title']))
                    $this->output('<SPAN CLASS="'.$class.'-who-title">'.$post['who']['title'].'</SPAN>');

                // You can also use $post['level'] to get the author's privilege level (as a string)

                if (isset($post['who']['points'])) {
                    $post['who']['points']['prefix']='('.$post['who']['points']['prefix'];
                    $post['who']['points']['suffix'].=')';
                    $this->output_split($post['who']['points'], $class.'-who-points');
                }

                if (strlen(@$post['who']['suffix']))
                    $this->output('<SPAN CLASS="'.$class.'-who-pad">'.$post['who']['suffix'].'</SPAN>');

                $this->output('</SPAN>');
            }
        }
4

3 回答 3

0

I still don´t understand your question.

If you want to use a variable in the function from outside you should declare it as global

global $variable;

If you want to get the return statement you just have to write

$result=post_meta_who("example","example");

Greets

于 2013-02-04T09:01:39.363 回答
0
$obj->post['who']['points']
于 2013-02-04T09:09:04.770 回答
0

看起来好像需要$post 通过引用传入。

为此,将函数声明更改为如下所示:

function post_meta_who(&$post, $class) {
    ...
}

与号(&)通过引用传入变量,因此对方法内部所做的任何更改$post都会对方法外部的变量产生影响。

我希望这有助于回答你的问题。

于 2013-02-04T09:15:57.923 回答