在php

时间:2017-10-20 15:27:13

标签: php codeigniter

foreach ($ids as $key => $value) {

            $settlement_data = $this->settlement_model->getSettlementData($value);

            foreach ($settlement_data as $key_date => $price) {
                $temp[] = array($key_date, (float)$price['settlement_price']);
            }

            $this->load->library('xlsxwriter');
            $file = new XLSXWriter();

            $first_row = array();
            if ($temp) {
                $first_row = array_fill(0, count($temp[0]), "");
            }
            //add one empty row at the beginning of array
            array_unshift($temp, $first_row);

            //add title row at the beginning of array (above the empty one)
            $title = 'test title';

            $file->writeSheet(array_values($temp), 'Mytest', $headers, $title);
            $file->downloadAsFile('test' . ".xlsx");
            die();
        }

$结算数据的样本数据如下:

array(7571) {
  ["2017-05-20"]=>
  array(4) {
    ["settlement_price"]=>
    string(15) "10.001"

  }
  ["2017-05-21"]=>
  array(4) {
    ["settlement_price"]=>
    string(14) "15.726"
  }
  ["2017-05-22"]=>
  array(4) {
    ["settlement_price"]=>
    string(15) "15.729352220997"

  }

现在只写一个id的日期和价格写入excel文件。如何写出与日期对应的其他ID的价格?

示例:

Date         Price of id1       price of id2
2017-05-20   10.001             20.001
2017-05-21   15.726             70.001

0 个答案:

没有答案