PHP 函数帮助

发布于 2024-08-22 07:41:25 字数 1424 浏览 3 评论 0原文

我已经编写了这段代码,它输出 $USER 的 profile_display_fields

$appearance = profile_display_fields($USER->id);
        if (empty($appearance)) {
            //Do nothing
        } else {
            foreach ($appearance as $c) {
            $custom .= '<a href=\''.$CFG->wwwroot.'/course/view.php?id='.$c->id.'\'>'.$c->fullname.'</a>';
            }
        }

这是我正在使用的函数:

function profile_display_fields($userid) {
    global $CFG, $USER;

    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
        foreach ($categories as $category) {
            if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
                foreach ($fields as $field) {
                    require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
                    $newfield = 'profile_field_'.$field->datatype;
                    $formfield = new $newfield($field->id, $userid);
                    if ($formfield->is_visible() and !$formfield->is_empty()) {
                        print_row(s($formfield->field->name.':'), $formfield->display_data());
                    }
                }
            }
        }
    }
}

我想做的是尝试一些 var_dump code>s 输出正确的数据。

但是任何人都可以帮助我识别变量吗?

I've written this piece of code, which outputs the profile_display_fields for the $USER:

$appearance = profile_display_fields($USER->id);
        if (empty($appearance)) {
            //Do nothing
        } else {
            foreach ($appearance as $c) {
            $custom .= '<a href=\''.$CFG->wwwroot.'/course/view.php?id='.$c->id.'\'>'.$c->fullname.'</a>';
            }
        }

Here is the function I'm using:

function profile_display_fields($userid) {
    global $CFG, $USER;

    if ($categories = get_records_select('user_info_category', '', 'sortorder ASC')) {
        foreach ($categories as $category) {
            if ($fields = get_records_select('user_info_field', "categoryid=$category->id", 'sortorder ASC')) {
                foreach ($fields as $field) {
                    require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
                    $newfield = 'profile_field_'.$field->datatype;
                    $formfield = new $newfield($field->id, $userid);
                    if ($formfield->is_visible() and !$formfield->is_empty()) {
                        print_row(s($formfield->field->name.':'), $formfield->display_data());
                    }
                }
            }
        }
    }
}

What I'm looking to do is try some var_dumps to output the correct data.

However can anyone help me identify the variables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-08-29 07:41:25

在您的函数中,您没有返回任何值,但在代码中,您已经为该函数分配了一个变量:

$appearance = profile_display_fields($USER->id);

您需要从函数返回一些变量/数据,这是要转储 var 的变量/数据。

我想您正在使用 print_row打印数据,而不是返回要在函数外使用的响应。

In your function you are not returning any value but above that in your code, you have assigned a variable to this function:

$appearance = profile_display_fields($USER->id);

You need to return some variable/data from the function and that is the one to be var dumped.

I suppose you are using the print_row to print the data, not returning the response to be used out of the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文