php - Loop through array and print out array values

878

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

285

Answer

Solution:

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";
}

People are also looking for solutions to the problem: php - ftp_put sends incomplete file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.