Вопрос

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

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top