0

如何使用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'];}

但它不起作用。

4

3 回答 3

2

我明白了,感谢 Grzegorz,这是解决方案:

foreach ($wartosci as $value)
        {
        echo $value->FieldName;
        }
于 2012-08-30T22:37:08.260 回答
1

因为它不是数组对象,而是 std 对象,所以你不能用它来调用它$array['key']

对于数组变量。

foreach ($wartosci as $value)
    { echo $value['FieldName']; }

对于标准对象。

foreach ($wartosci as $value)
    { echo $value->FieldName; }
于 2012-09-02T06:27:09.237 回答
0

在请开发人员帮助您之前,您应该先在 Internet 上进行搜索。

这是手册: http: //php.net/manual/en/control-structures.foreach.php

于 2012-08-30T22:29:16.193 回答