PHP輸出表格

來源:互聯網
上載者:User
現有資料如下:

麵包紙杯 DPK219 VAC001 1.00
麵包紙杯 DPK219 VBW001 1.00
罐裝蟹肉 1磅/罐 RCN061-1 VAC001 2.00
罐裝蟹肉 1磅/罐 RCN061-1 VBW001 2.00
牛淋片5mm RFB300-2 VAC001 3.00
牛淋片5mm RFB300-2 VBW001 3.00
厚牛淋片 RFB300-3 VAC001 4.00
厚牛淋片 RFB300-3 VBW001 4.00

需求是輸出一個表格(類似excel),所有同款產品的資訊用一行輸出,一共四行,如下:

麵包紙杯 1.00 1.00
罐裝蟹肉 1磅/罐 2.00 2.00
牛淋片5mm 3.00 3.00
厚牛淋片 4.00 4.00

菜鳥菜問題,勿怪。

回複內容:

現有資料如下:

麵包紙杯 DPK219 VAC001 1.00
麵包紙杯 DPK219 VBW001 1.00
罐裝蟹肉 1磅/罐 RCN061-1 VAC001 2.00
罐裝蟹肉 1磅/罐 RCN061-1 VBW001 2.00
牛淋片5mm RFB300-2 VAC001 3.00
牛淋片5mm RFB300-2 VBW001 3.00
厚牛淋片 RFB300-3 VAC001 4.00
厚牛淋片 RFB300-3 VBW001 4.00

需求是輸出一個表格(類似excel),所有同款產品的資訊用一行輸出,一共四行,如下:

麵包紙杯 1.00 1.00
罐裝蟹肉 1磅/罐 2.00 2.00
牛淋片5mm 3.00 3.00
厚牛淋片 4.00 4.00

菜鳥菜問題,勿怪。

為了給你一個例子就混編了。

 '麵包紙杯', 'typeA' => 'DPK219', 'typeB' => 'VAC001', 'price' => '1.00'),        array('catogary' => '麵包紙杯', 'typeA' => 'DPK219', 'typeB' => 'VBW001', 'price' => '1.00'),        array('catogary' => '罐裝蟹肉 ', 'typeA' => 'RCN061-1', 'typeB' => 'VAC001', 'price' => '2.00'),        array('catogary' => '罐裝蟹肉 ', 'typeA' => 'RCN061-1', 'typeB' => 'VBW001', 'price' => '2.00'),        array('catogary' => '牛淋片5mm', 'typeA' => 'RFB300-2', 'typeB' => 'VAC001', 'price' => '3.00'),        array('catogary' => '牛淋片5mm', 'typeA' => 'RFB300-2', 'typeB' => 'VBW001', 'price' => '3.00'),        array('catogary' => '厚牛淋片', 'typeA' => 'RFB300-3', 'typeB' => 'VAC001', 'price' => '4.00'),        array('catogary' => '厚牛淋片', 'typeA' => 'RFB300-3', 'typeB' => 'VBW001', 'price' => '4.00'),    );    $tableInfo = array();    // $tableInfo = array_column($info, 'catogary', 'price');//if php version > 5.5    foreach($info as $item)        $tableInfo[$item['catogary']] = $item['price'];?>    

大體講下思路,先把資料存在數組 info 內,然後對數組進行過濾,取出需要展示在表格內的有用資料到一個新數組 tableInfo 內。接著,遍曆新數組將資料輸出到表格 table 內即可。如下:

  • $price) {?>

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.