Php 如何从子阵列获取所有值?
我很困惑,因为我没有得到我想要的。打印阵列时(使用Php 如何从子阵列获取所有值?,php,arrays,multidimensional-array,teamspeak,Php,Arrays,Multidimensional Array,Teamspeak,我很困惑,因为我没有得到我想要的。打印阵列时(使用echo' Array ( [uid] => TeamSpeak3_Helper_String Object ( [string:protected] => (hidden for public) [position:protected] => 0 ) [ip] => TeamSpeak3_Helper_String Obje
echo'
Array
(
[uid] => TeamSpeak3_Helper_String Object
(
[string:protected] => (hidden for public)
[position:protected] => 0
)
[ip] => TeamSpeak3_Helper_String Object
(
[string:protected] => (hidden for public)
[position:protected] => 0
)
[nick] => TeamSpeak3_Helper_String Object
(
[string:protected] => (hidden for public)
[position:protected] => 0
)
[dbid] => 5
[mytsid] => TeamSpeak3_Helper_String Object
(
[string:protected] => (hidden for public)
[position:protected] => 0
)
[sgroups] => Array
(
[0] => TeamSpeak3_Helper_String Object
(
[string:protected] => 0,1,2,3,4
[position:protected] => 0
)
)
)
我可以使用echo$client_properties['uid'];
获取特定值,但它仍然是最后一个索引。
如何获取第一个索引,如$client\u properties[0]['uid']
编辑
数组将填充以下代码:
foreach($ts3server->clientList()作为$tsClient){
$client_properties=array(
'uid'=>$tsClient->getInfo()['client\u unique\u identifier'],
'ip'=>$tsClient->getInfo()['connection\u client\u ip'],
'nick'=>$tsClient->getInfo()['client_昵称'],
'dbid'=>$tsClient->getInfo()['client\u database\u id'],
'mytsid'=>$tsClient->getInfo()['client\u myteamspeak\u id'],
'sgroups'=>数组(
$tsClient->getInfo()['client\u servergroups']
)
);
}
现在我知道了问题所在……如果我以前添加了一些值,我只会覆盖$client\u properties
中的值。
所以我需要的是array\u push()
。
正确的解决方案应该是:
$clients=array();
//弗雷奇
数组\u推送($clients,$client\u属性);
要获得特定的值,我应该使用echo$clients[0]['uid']
为什么你认为该数组中还有其他元素?print\u r
打印整个元素,而不仅仅是当前元素。正如@TimRoberts所说的,如果print\u r
打印你共享的内容,那就是整个数组。尝试发布负责创建数组的代码,登录到ho上可能会有一个流程创建的数组每次都会覆盖元素,而不是添加新元素。我已经编辑了我的帖子。也许我应该睡觉了。。。