Php 循环Json数组

Php 循环Json数组,php,arrays,json,foreach,Php,Arrays,Json,Foreach,我有这种json数组 [result] => success [totalresults] => 20 [startnumber] => 0 [numreturned] => 20 [invoices] => Array ( [invoice] => Array ( [0] => Array

我有这种json数组

[result] => success
    [totalresults] => 20
    [startnumber] => 0
    [numreturned] => 20
    [invoices] => Array
        (
            [invoice] => Array
                (
                    [0] => Array
                        (
                            [id] => 2014088828
                            [userid] => 1
                            [firstname] => Rony
                            [lastname] => Raymaekers
                            [companyname] => Raymaekers Rony
                            [invoicenum] => 
                            [date] => 2014-11-19
                            [duedate] => 2014-12-03
                            [datepaid] => 0000-00-00 00:00:00
                            [subtotal] => 49.59
                            [credit] => 0.00
                            [tax] => 10.41
                            [tax2] => 0.00
                            [total] => 60.00
                            [taxrate] => 21.00
                            [taxrate2] => 0.00
                            [status] => Unpaid
                            [paymentmethod] => paypal
                            [notes] => 
                            [currencycode] => EUR
                            [currencyprefix] => €
                            [currencysuffix] => EUR
                        )
我想把发票列在html表格上

id、到期日、状态、付款方式

请帮助如何循环此数组

我试过了

$invoice = json_decode($invoices);
    foreach($invoices as $keys) {
         foreach($keys as $invoice => $kom) {
           echo $kom['id'];

      }

      }

但是不起作用

您有一个语法错误

foreach ($array as $key => $value)
我也不认为你的循环是正确的

$array['invoices']['invoice'] 
从代码的外观来看,应该是foreach中的数组

$data=json\u解码($invoices);
$data = json_decode($invoices);

foreach($data['invoices'] as $invoice){
   echo "<tr>";
   echo "<td>{$invoice['id']}</td>";
   echo "<td>{$invoice['user_id']}</td>";
   echo "<td>{$invoice['firstname']}</td>";
   echo "<td>{$invoice['lastname']}</td>";
   // and so on
   echo "</tr>";
}
foreach($data['invoices']作为$invoice){ 回声“; 回显“{$invoice['id']}”; 回显“{$invoice['user_id']}”; 回显“{$invoice['firstname']}”; 回显“{$invoice['lastname']}”; //等等 回声“; }
@lainard你能试试var_dump(json_decode($invoices));给我结果,你可以提供实际的JSON。