首页 > 解决方案 > 在php中将数组转换为html表

问题描述

我有一个由 API 生成的数组,我使用带有 php 5.6 的 cpanel 托管。

我尝试了很多组合但没有用

该数组由 emag 市场 API 生成。

代码看起来像

Array
(
    [isError] => 
    [messages] => Array
        (
        )

    [results] => Array
        (
            [0] => Array
                (
                    [vendor_name] => WISE COMPUTER SRLD
                    [id] => 2003677675
                    [parent_id] => 
                    [date] => 2017-05-21 10:55:18
                    [payment_mode] => RAMBURS
                    [payment_mode_id] => 1
                    [delivery_mode] => CURIER RO
                    [observation] => 
                    [status] => 4
                    [payment_status] => 0
                    [customer] => Array
                        (
                            [id] => 994041
                            [mkt_id] => 994041
                            [name] => Cristina Manuela Dancas
                            [company] => Cristina Manuela Dancas
                            [gender] => 
                            [phone_1] => 0743073616
                            [phone_2] => 
                            [phone_3] => 
                            [registration_number] => 
                            [code] => 
                            [email] => 
                            [billing_name] => 
                            [billing_phone] => 
                            [billing_country] => RO
                            [billing_suburb] => Bucuresti
                            [billing_city] => Sectorul 1
                            [billing_locality_id] => 2
                            [billing_street] => Str. Aviator Sanatescu nr. 57, parter, Ap1
                            [billing_postal_code] => 
                            [shipping_country] => RO
                            [shipping_suburb] => Bucuresti
                            [shipping_city] => Sectorul 1
                            [shipping_locality_id] => 2
                            [shipping_postal_code] => 
                            [shipping_contact] => Cristina Manuela Dancas
                            [shipping_phone] => 0743073616
                            [created] => 2017-05-21 10:55:19
                            [modified] => 2017-05-21 10:56:21
                            [bank] => 
                            [iban] => 
                            [legal_entity] => 0
                            [fax] => 
                            [is_vat_payer] => 1
                            [liable_person] => 
                            [shipping_street] => Str. Aviator Sanatescu nr. 57, parter, Ap1
                        )

我在 HTML 表中使用 php 转换什么。

需要一些帮助。如果您需要更多信息,请留言。

标签: phparrays

解决方案


这是我从 PHP 数组创建 HTML 表格的快速解决方案。本质是,二维数组变成了一个有意义的表。您的数组似乎更复杂,因此转换为有用的表可能需要更多的努力。

    $data = array(  array("ID","Firstname","Lastname","Phone"),
                    array("1","John","Jenkins","+91375953"),
                    array("2","Eduard","Kenny","+7244277"),
                    array("3","Anita","Beaumont","+427427427"),
                    array("4","Wanda","Wade","+274274247"),
                    array("4","Sarah","Colon","+835835"),
                );


    echo '<table border="1">';
    foreach($data as $row) {
        echo '<tr>';
        foreach($row as $cell) {
            echo '<td>'.$cell.'</td>';
        }
        echo '</tr>';
    }
    echo '</table>';

推荐阅读