Outputting multidimensional json array to table php [multiple values]

倾然丶 夕夏残阳落幕 提交于 2019-12-11 11:36:40

问题


I have been at this for the last 9 days and can't for the life of me figure this one out.

It starts by obtaining the JSON array via cURL

$result = curl_exec($h);
curl_close($h);
var_dump(json_decode($result, true));

The output with < pre> and < /pre> is as so:

array(1) {
["SE"]=>
array(4) {
    ["errors"]=>
    array(0) {
    }
    ["billwith"]=>
    string(10) "removedInteger"
    ["bill_detail"]=>
    array(1) {
        ["bill_item"]=>
        array(48) {
          [0]=>
          array(7) {
            ["type1identifier_id"]=>
            string(5) "removed coded string "
            ["prod"]=>
            string(15) "removed string"
            ["charge"]=>
            string(4) "1.36"
            ["misc_date"]=>
            string(6) "063014"
            ["misc_date2"]=>
            string(6) "000000"
            ["notes"]=>
            string(0) ""
            ["color"]=>
            string(4) "hide"
          }
          [1]=>
          array(7) {
          ["type1identifier_id""]=>
          string(5) "CP024"
          ["prod"]=>
          string(15) "removed string "
          ["charge"]=>
          string(3) ".00"
          ["misc_date"]=>
          string(6) "063014"
          ["misc_date2"]=>
          string(6) "000000"
          ["notes"]=>
          string(0) ""
          ["color"]=>
          string(4) "hide"

I'm trying to write this information to a table so that it is legible, such as "removed string" is one of the values I wish to write/echo in a tag, but I can't seem to dereference any of it in this mess.

Any help is greatly appreciated, thank you!

One last update, when comparing, it returns false each time, not too sure why, do i need to declare my values first? Here is the code I'm using:

if ($bill_item['charge'] == "attention")
{
    echo '<tr bgcolor="red">';
    echo '<td>';
    echo 'charge amount DOES equal attention';
    echo '</td>';
}
  else
  {
    echo '<tr bgcolor="white">';
    echo '<td>';
    echo 'charge amount does NOT equal attention';
    echo '</td>';
  }

回答1:


Just access the decoded json that turned into array as you normally would:

foreach($result['SE']['bill_detail']['bill_item'] as $bill_item) {
    // do what you have to do
    echo $bill_item['prod'] . '<br/>';
}


来源:https://stackoverflow.com/questions/26824157/outputting-multidimensional-json-array-to-table-php-multiple-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!