0

I have array of object if I using print_r looks like :

    Array
    (
        [0] => stdClass Object
            (
                [name] => User1
                [user_id] => 1
                [email] => [email protected]
            )

        [1] => stdClass Object
            (
                [name] => User2
                [user_id] => 2
                [email] => [email protected]
            )

        [2] => stdClass Object
            (
                [name] => User3
                [user_id] => 3
                [email] => [email protected]
            )
     )

I want to loop and show them using Twig Engine then access member of object like name, email using Twig Engine too. How do that? I was tried but always error. I'm new about Twig.

4
  • what did you tried?? Commented Apr 4, 2017 at 7:53
  • @MASIDDIQUI I want to access member of object like name or email or user_id. I want to show them as html like <li>. And also with these value I will use one of them for another proses. Commented Apr 4, 2017 at 7:58
  • Possible duplicate of How to access a member of an stdClass in PHP that starts with an @ Commented Apr 4, 2017 at 8:20
  • 1
    @UgyAstro if you would include at least some code showing HOW you try to access them, it would be easier for others to help you. Commented Apr 4, 2017 at 8:54

2 Answers 2

1

Try this in Twig

{% for user in users %}
    <li><span>{{ user.name }}</span><span>{{ user.email}}</span></li>
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$object = your Std class Object;

foreach($object as $data)
{
    echo $data->name;
    echo $data->user_id;
    echo $data->email;
}

In twig you can use it like:

{% for user in users %}
    <li><span>{{ user.name }}</span><span>{{ user.email}}</span></li>
{% endfor %}

Comments

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.