1

Sorry i dont have anything to show on this but everything i have tried fails.

I have an array which is returned as part of an object. I need to loop through the values and place them in variables then print them on the page.

[Required] => Array
    (
        [0] => stdClass Object
            (
                [Field] => Field1
                [Question] => Question1
                [DataType] => Boolean
            )

        [1] => stdClass Object
            (
                [Field] => Field2
                [Question] => Question2
                [DataType] => varchar
            )

        [2] => stdClass Object
            (
                [Field] => Field3
                [Question] => Question3
                [DataType] => Boolean
            )

        [3] => stdClass Object
            (
                [Field] => Field4
                [Question] => Question5
                [DataType] => Int
            )

    )

so for example i would like to print out

Field1 is Boolean Field2 is varchar.. etc

Your kind assistance will be greatly appreciated

1 Answer 1

4

Required is an object property, so use $object->Required... it's values are an array, so use foreach; the elements you want are also properties, so

foreach($object->Required as $needed) {
    echo $needed->Field,' is ',$needed->DataType,"\n";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. This works and i learned a lot about how to handle this sort of data. Very much appreciated.

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.