0

How to get values from this array, which had std objects, using 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 I need ['FieldName'] I tryed

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

But it is not working.

1

3 Answers 3

2

I got it, thanks to Grzegorz, here is solution:

foreach ($wartosci as $value)
        {
        echo $value->FieldName;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Everyone knows where the php manual, no need to thanks for those
1

Because it isn't an array object, but std object you can't call it with $array['key']

for an array variable.

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

for a standard object.

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

Comments

0

You should really search on the Internet first before asking developers to help you.

Here is the manual: http://php.net/manual/en/control-structures.foreach.php

3 Comments

I know where is manual, but is not simple array, it contains std objects, and thats why I don't know how to get it
@saleemahmed: Can you post an explanation why? Especially that Ariel did not object, upvoted me, mentioned me as the source of the answer, and this how this is done in stackoverflow?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.