我想从这个 php 数组中得到一个特定的值

i want to get a specific value from this php array

我是 Moodle 开发的新手,目前我正在创建一个新的自定义块,它将显示用户注册的当前课程。我能够使用此功能获取用户注册的当前课程:

$courses = enrol_get_my_courses();

但目前我无法从该函数返回的数组中提取课程全名。

数组的结果是:

array(1) { [3]=> object(stdClass)#581 (11) { ["id"]=> string(1) "3" ["category"]=> string(1) "1" ["sortorder"]=> string(5) "20001" ["shortname"]=> string(3) "CAT" ["fullname"]=> string(4) "Cat2" ["idnumber"]=> string(0) "" ["startdate"]=> string(10) "1460757600" ["visible"]=> string(1) "0" ["groupmode"]=> string(1) "0" ["groupmodeforce"]=> string(1) "0" ["cacherev"]=> string(10) "1460882387" } } 

所以我只想从上一个数组中获取 ["fullname"] 值。

由于您将一个对象封装到数组中,您可以像这样访问它的值:

$courses[3]->fullname

数组值以这种方式访问​​:

$array['key']

对象值的访问方式如下:

$object->key