2016-12-28 84 views
0

我有一個json_encode格式的數據庫值。echo json_decode php中的數據

[["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"]] 

我想在表格中顯示它的json_decode格式。

$options = json_decode($options, true); 

然後我試圖把它放在foreach循環:

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

和輸出僅僅是Array

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

print_r()回報:

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 
     ) 

) 

但它並不好看。這是更好和簡單的方法來在php中回顯json_decode數據?

+2

你有一個數組的數組,所以你可以嘗試foreach($ options [0]作爲$ value),看看是否有效。 – jeff

+0

你想要哪種數據? – 2016-12-28 06:47:04

回答

0

這將在表格中打印數據。

$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>";