0

Below are the results from PHP JSON encoded file.

[{"type":"pie","name":"Class","data":[["Nari",70],["Giri",45],["Balu",25],["Babu",82]]}]

I want to print data values into two column table.

| nari | 70 |  
| giri | 45 |   
| balu | 25 |  
| babu | 82 |   
3
  • 2
    What you have tried so far Commented Dec 19, 2015 at 12:38
  • This problem is a really easy one, so please incluse what you already tried like @Uchiha asked. This problem has been solved and been documented before, it just takes a quick search for you to solve it on your own, if you still fail after attempting what you found, you can come here and ask about a specific problem in your code rather than asking the community to solve your problem without trying yourself. Commented Dec 19, 2015 at 12:45
  • Use json decode u will get an array with associative Commented Dec 19, 2015 at 13:06

1 Answer 1

1

It's a pitty that you don't show you attempts so far. On the other hand it's shortly before christmas so...

$json = '[{"type":"pie","name":"Class","data":[["Nari",70],["Giri",45],["Balu",25],["Babu",82]]}]';
$object = json_decode($json);
foreach($object[0]->data as $row) {
  echo "|".strtolower($row[0])."|".strtolower($row[1])."|<br>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Either OP added the jquery tag falsely or he gets his JSON from his PHP service and wants to decode and add it to his HTML with jQuery rather than load the complete HTML in his PHP service.

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.