我正在尝试回显当前用户的character_name。如何获得这个是通过使用default_character_id并运行字符列表并获取该字符的名称。然后在下面显示一个下拉菜单,其中包含characters属性中的其他字符。
关于如何实现这一目标的任何想法?
object(stdClass)#26 (18) {
["user_id"]=>
string(5) "10004"
["role_id"]=>
string(1) "4"
["default_character_id"]=>
string(1) "1"
["characters"]=>
array(3) {
[0]=>
object(stdClass)#30 (6) {
["id"]=>
string(1) "3"
["character_name"]=>
string(5) "twilliams"
["user_id"]=>
string(5) "10004"
}
[1]=>
object(stdClass)#31 (6) {
["id"]=>
string(1) "4"
["character_name"]=>
string(4) "ksmith"
["user_id"]=>
string(1) "0"
}
[2]=>
object(stdClass)#32 (6) {
["id"]=>
string(1) "5"
["character_name"]=>
string(11) "tjones"
["user_id"]=>
string(1) "0"
}
}
}
<a href="" data-toggle="dropdown" class="glyphicons cogwheel">
<i></i>
<?php
//echo character name of logged in user
?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu pull-right">
<li><a href="">Some option</a></li>
<li><a href="">Some other option</a></li>
<li><a href="">Other option</a></li>
</ul>
答案 0 :(得分:2)
<a href="" data-toggle="dropdown" class="glyphicons cogwheel">
<i></i>
<?php
echo $object->characters[$object->default_character_id]->charachter_name;
?>
<span class="caret"></span>
</a>
<ul class="dropdown-menu pull-right">
<li><a href="">Some option</a></li>
<li><a href="">Some other option</a></li>
<li><a href="">Other option</a></li>
</ul>