0

I can't figure out how to do the following: I retrieve a mysql request as as json and I get this:

[
    {"pid":"1","comment":"La premiere consultation est toujours bizarre..."},
    {"pid":"1","comment":"La seconde... c'est jamais mieux !"}
]

and now I'm trying to loop through that to generate my html template. I'm absolutely not a php expert but learning :)

Thanks for your help !

1
  • 5
    Use json_decode() to convert it to a PHP array, and then simply use foreach() to loop through it Commented Dec 13, 2015 at 22:57

1 Answer 1

1
 Thank you Mark, this worked out fine !

$arr = json_decode($json, true);

 foreach($arr as $item) { //foreach element in $arr
    echo 'Comment: ' . $item['comment'];
 }
Sign up to request clarification or add additional context in comments.

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.