Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中打印多维数组_Php - Fatal编程技术网

如何在php中打印多维数组

如何在php中打印多维数组,php,Php,可能重复: 我有一个数组,格式如下 Array ( [0] => Array ( [product_id] => 33 [amount] => 1 ) [1] => Array ( [product_id] => 34 [amount] => 3 ) [2] => Array ( [product_id] => 10 [amount] => 1 ) ) 数组([0]=>Array([product\u id]=>33[amount]=>1)[1]=>Array([product\u id]=>

可能重复:

我有一个数组,格式如下

Array ( [0] => Array ( [product_id] => 33 [amount] => 1 ) [1] => Array ( [product_id] => 34 [amount] => 3 ) [2] => Array ( [product_id] => 10 [amount] => 1 ) ) 数组([0]=>Array([product\u id]=>33[amount]=>1)[1]=>Array([product\u id]=>34[amount]=>3)[2]=>Array([product\u id]=>10[amount]=>1)) 我希望从该数组中获得如下格式的输出

Product ID Amount 33 1 34 3 10 1 产品ID数量 33 1 34 3 10 1 有人能帮我解决这个问题吗。变量的var_转储为

array 0 => array 'product_id' => string '33' (length=2) 'amount' => string '1' (length=1) 1 => array 'product_id' => string '34' (length=2) 'amount' => string '3' (length=1) 2 => array 'product_id' => string '10' (length=2) 'amount' => string '1' (length=1) 排列 0 => 排列 'product_id'=>字符串'33'(长度=2) '金额'=>字符串'1'(长度=1) 1 => 排列 'product_id'=>字符串'34'(长度=2) '金额'=>字符串'3'(长度=1) 2 => 排列 'product_id'=>字符串'10'(长度=2) '金额'=>字符串'1'(长度=1) 试试这个

foreach($arr as $a)
{
    echo $a['product_id'];
    echo $a['amount'];
}

按照您的要求格式化。

我相信这是您的阵列

$array = Array ( 
        0 => Array ( "product_id" => 33 , "amount" => 1 ) ,
        1 => Array ( "product_id" => 34  , "amount" => 3 ) ,
        2 => Array ( "product_id" => 10  , "amount" => 1 ) );
使用
foreach

echo "<pre>";
echo "Product ID\tAmount";
foreach ( $array as $var ) {
    echo "\n", $var['product_id'], "\t\t", $var['amount'];
}
Product ID  Amount
33          1
34          3
10          1
输出


产品Id
阿蒙

basic loop这里有两千个答案,我相信其中一个会有帮助。非常感谢,这也很有效。
Product ID  Amount
33          1
34          3
10          1
     <table>
        <tr>
            <th>Product Id</th>
            <th>Ammount</th>
        </tr>

        <?php
        foreach ($yourArray as $subAray)
        {
            ?>
            <tr>
                <td><?php echo $subAray['product_id']; ?></td>
                <td><?php echo $subAray['amount']; ?></td>
            </tr>
            <?php
        }
        ?>
    </table>