如何使用foreach从这个具有std对象的数组中获取值?
Array (
[0] => stdClass Object (
[SubmissionValueId] => 28
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Typ
[FieldValue] => Panoramiczny
)
[1] => stdClass Object (
[SubmissionValueId] => 29
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Producent
[FieldValue] => sony
)
[2] => stdClass Object (
[SubmissionValueId] => 30
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Model
[FieldValue] => sony
)
[3] => stdClass Object (
[SubmissionValueId] => 31
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Rok produkcji
[FieldValue] => 1993
)
[4] => stdClass Object (
[SubmissionValueId] => 32
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Nr seryjny
[FieldValue] => sdadas
)
[5] => stdClass Object (
[SubmissionValueId] => 33
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Nr seryjny lampy
[FieldValue] => sdadsd
)
[6] => stdClass Object (
[SubmissionValueId] => 34
[FormId] => 3
[SubmissionId] => 4
[FieldName] => data2
[FieldValue] => 05.08.2012
)
[7] => stdClass Object (
[SubmissionValueId] => 35
[FormId] => 3
[SubmissionId] => 4
[FieldName] => Wyslij
[FieldValue] => Wyślij
)
[8] => stdClass Object (
[SubmissionValueId] => 36
[FormId] => 3
[SubmissionId] => 4
[FieldName] => formId
[FieldValue] => 3
)
)
F.ex我需要['FieldName']我试过
foreach ($wartosci as $value)
{ echo $value['FieldName'];}
但它没有用。
答案 0 :(得分:2)
我知道了,感谢Grzegorz,这里有解决方案:
foreach ($wartosci as $value)
{
echo $value->FieldName;
}
答案 1 :(得分:1)
因为它不是一个数组对象,而是std对象,你不能用$array['key']
表示数组变量。
foreach ($wartosci as $value)
{ echo $value['FieldName']; }
用于标准对象。
foreach ($wartosci as $value)
{ echo $value->FieldName; }
答案 2 :(得分:0)
在请求开发人员帮助您之前,您应该首先在互联网上搜索。
以下是手册:http://php.net/manual/en/control-structures.foreach.php