2012-08-30 54 views
0

如何使用foreach從該數組中獲取std對象的值?從數組中獲得foreach值

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我需要[ '字段名']我tryed

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

但它無法正常工作。

+1

[你嘗試過什麼?](http://www.whathaveyoutried.com) – Kermit

回答

0

在開發人員要求幫助之前,您應該首先在互聯網上進行搜索。

下面是本手冊:http://php.net/manual/en/control-structures.foreach.php

+0

我知道哪裏是手動的,但不是簡單的數組,它包含性病對象,這就是爲什麼我不知道如何得到它 – ariel

+0

@ariel:試試這個:http://stackoverflow.com/questions/5875785/how-to-access-stdclass-object-after-a-specific-key-value-pair – Grzegorz

+0

@saleemahmed:你能爲什麼發佈解釋?特別是Ariel沒有反對,提出了我的意見,提到我是答案的來源,而這是如何在stackoverflow中完成的? – Grzegorz

2

我得到了它,多虧格熱戈日,這裏是解決方案:

foreach ($wartosci as $value) 
     { 
     echo $value->FieldName; 
     } 
+0

大家都知道php手冊在哪裏,不用多謝那些 –

1

因爲它不是一個數組對象,但對象性病,你不能打電話它與$array['key']

爲數組變量。

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

爲標準對象。

foreach ($wartosci as $value) 
    { echo $value->FieldName; }