Php 按值访问数组元素
我有这样一个数组:Php 按值访问数组元素,php,Php,我有这样一个数组: stdClass Object ( [223] => Array ( [0] => stdClass Object ( [tribeName] => TTTT [tribeid] => 31 [numusers] => 10
stdClass Object
(
[223] => Array
(
[0] => stdClass Object
(
[tribeName] => TTTT
[tribeid] => 31
[numusers] => 10
[dateCreated] => 2012-05-28 18:30:34
)
[1] => stdClass Object
(
[tribeName] => KKKKK
[tribeid] => 32
[numusers] => 11
[dateCreated] => 2012-05-28 18:32:12
)
[2] => stdClass Object
(
[tribeName] => RRRR
[tribeid] => 33
[numusers] => 5
[dateCreated] => 2012-05-28 18:53:17
)
[3] => stdClass Object
(
[tribeName] => mytehhhhhst2
[tribeid] => 34
[numusers] => 4
[dateCreated] => 2012-05-28 18:56:15
)
[4] => stdClass Object
(
[tribeName] => yog
[tribeid] => 58
[numusers] => 1
[dateCreated] => 2012-06-01 12:32:47
)
[5] => stdClass Object
(
[tribeName] => newFunc
[tribeid] => 63
[numusers] => 1
[dateCreated] => 2012-06-01 12:45:01
)
[6] => stdClass Object
(
[tribeName] => Jghj
[numusers] => 0
[tribeid] =>
)
)
)
这里,223是键值,每次都是新的。我以密钥($array)的形式访问它。我将得到223个值。
但是我如何访问它的值,例如tribeName?请帮帮我
谢谢。好的,您必须迭代数组并手动检查每个元素。 当然,您也可以为此编写函数 如果需要比较整个数组元素,而不仅仅是其中的一个元素,可以使用来确定键。试试这个
foreach ($array as $value) {
foreach($value as $data )
echo $data->tribeName;
}
试试这个
foreach($var as $key => $val)
{
$kkv = $var[$key];
$inarray = $kkv[0];
print_r($inarray);
echo $inarray['tribeName'];
}