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

图片转代码服务由CSDN问答提供 功能建议

我从基本的php有一个非常简单的问题。

在moodle中,我在php中做了这个

  print_r($ USER)
   
 \  n 

获取$ USER变量传递的所有信息(下面的代码片段,我认为它是数组)

  stdClass Object([id] => 4  [auth] =>电子邮件[确认] => 1 [policyagreed] => 0 [已删除] => 0 [已暂停] => 0 [mnethostid] => 1 [用户名] => testowy [  idnumber] => [firstname] =>名字[lastname] => Testowy [email] => aaa@aaa.pl [emailstop] => 0 [icq] => [skype] => [  yahoo] => [目标] => [msn] => [phone1] => [phone2] => [机构] => [部门] => [地址] => [城市]  => AAABBB [country] => PL [lang] => [calendartype] => gregorian [theme] => [timezone] => 99 [firstaccess] => 1392147531 [lastaccess] =>  1392927159 [lastlogin] => 1392841140> 
   
 
 

我想获得名为[firstname]的字段和字段[lastname]并将其置于联系表单中。有人可以 请写信给我 怎么做 ?

感谢您的帮助,最好的问候

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题