dqce48404 2014-02-20 20:17
浏览 16
已采纳

如何从moodle中的数组中获取字段

I have very simple question from basic php.

In moodle i did this in php

print_r($USER)

to get all info what is passed in $USER variable (scrap of code underneath, I think it's array)

stdClass Object ( [id] => 4 [auth] => email [confirmed] => 1 [policyagreed] => 0 [deleted] => 0 [suspended] => 0 [mnethostid] => 1 [username] => testowy [idnumber] => [firstname] => Firstname [lastname] => Testowy [email] => aaa@aaa.pl [emailstop] => 0 [icq] => [skype] => [yahoo] => [aim] => [msn] => [phone1] => [phone2] => [institution] => [department] => [address] => [city] => AAABBB [country] => PL [lang] => [calendartype] => gregorian [theme] => [timezone] => 99 [firstaccess] => 1392147531 [lastaccess] => 1392927159 [lastlogin] => 1392841140 >

I want to get field called [firstname] and field [lastname] and put it in contact form. Can somebody please write me how to do it ?

Thanks for help , best regards

  • 写回答

1条回答 默认 最新

  • dsjfrkvn818747 2014-02-20 20:29
    关注

    It is stdClass Object which is an object, not array. In php in order to get a value from an object, we use -> and in array we use [].

    Just do:

    $USER->firstname
    

    and

    $USER->lastname
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!