drasebt1835 2016-12-28 06:40
浏览 63

在php中回显json_decode数据

I have a value from database in json_encode format.

[["Size: 10x24 (+150)","Backing: Black","Lines: 1","Border: No Border","Border Color: ","Flashing: No Thanks","Outdoor: No","Vertical: No","contoured cut: No","qty: 1","Text 1: Custom","Line 1: Red","Font 1: Arial"]]

I want to display it's json_decode format in table.

$options = json_decode($options, true);

Then I am trying to put it in foreach loop:

foreach ($options as $value)
{
    echo $value, "
";
};

and the output is just Array.

echo('<pre>'); print_r($json); echo('</pre>'); 

print_r() returns:

Array
(
    [0] => Array
        (
            [0] => Size: 10x24 (+150)
            [1] => Backing: Black
            [2] => Lines: 1
            [3] => Border: No Border
            [4] => Border Color: 
            [5] => Flashing: No Thanks
            [6] => Outdoor: No
            [7] => Vertical: No
            [8] => contoured cut: No
            [9] => qty: 1
            [10] => Text 1: Custom
            [11] => Line 1: Red
            [12] => Font 1: Arial
        )

)

But it does not look good. which is the better and easy way to echo json_decode data in php?

  • 写回答

1条回答 默认 最新

  • dpnvrt3119 2016-12-28 06:55
    关注

    This will print data in table.

    $options = '[["Size: 10x24 (+150)","Backing: Black","Lines: 1","Border: No Border","Border Color: ","Flashing: No Thanks","Outdoor: No","Vertical: No","contoured cut: No","qty: 1","Text 1: Custom","Line 1: Red","Font 1: Arial"]]';
    $options = json_decode($options, true);
    echo "<table border='1'>";
    foreach ($options[0] as $value)
    {
        echo "<tr><td>";  
        echo $value;
        echo "</td></tr>";
    };
    echo "</table>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100