【问题标题】:How do I displayed in the table this array, with for?我如何在表格中显示这个数组,用for?
【发布时间】:2012-05-25 07:32:14
【问题描述】:
<?php 
$ex = array
(
    'Product' => array
        (
            '0' => array
                (
                    'item_id' => '1',
                    'product_name' => 'Paine',
                    'product_description' => 'Intermediala',
                    'product_price' => '2',
                    'product_weight' => '300',
                    'product_quantity' => '300',
                    'product_photos ' => '0',
                    'product_colors ' => '',
                ),

            '1' => array
                (
                  'item_id' => '2',
                    'product_name' => 'Apa',
                    'product_description' => 'plata',
                    'product_price' => '4',
                    'product_weight' => '4000',
                    'product_quantity' => '',
                    'product_photos' => '0',
                    'product_colors' => '',
                ),
            '2' => array
                (
                    'item_id' => '3',
                    'product_name' => 'Apa',
                    'product_description' => 'minerala',
                    'product_price' => '4',
                    'product_weight' => '4000',
                    'product_quantity' => '',
                    'product_photos' => '0',
                    'product_colors' => '',
                )   

        )
);



?>

【问题讨论】:

  • create_table($ex),不,我在开玩笑,没有内置函数,必须for循环
  • 认为您可能需要更清楚一点...
  • 是的,您可以使用 for 或 foreach 来实现
  • 到底是什么问题?

标签: php


【解决方案1】:
<table border="1"><?php
foreach ($ex['Product'] as $row) {
    echo '<tr>';
    echo '<td>'.$row['item_id'].'</td><td>'.$row['product_name'].'</td>';
    echo '</tr>';
}
?></table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    • 2011-02-15
    相关资源
    最近更新 更多