如何在Yii2中打印数组数据

时间:2015-07-02 19:04:42

标签: php

下午好!我试图将多个数组添加到单个数组中。这就是为什么我尝试生成一个csv文件并添加安排,因为新行被添加到.csv

静态示例:

$data = array(
            array( 'item' => 'Server',  'cost' => 10000, 'approved by' => 'Joe bebe'),
            array( 'item' => 'Mt Dew',  'cost' => 1.25,  'approved by' => 'John'),
            array( 'item' => 'Intelli', 'cost' => 500,   'approved by' => 'James')
);

$this -> outputCsv('document.csv', $data);

我想尝试这样的事情:

$array = ('Juan', 'Pedro', 'Luis')

$data = array(
foreach($array as $a):
         array( 'item' => $a,  'cost' => 10000, 'approved by' => 'Joe'),
endforeach;

 $this -> outputCsv('document.csv', $data);

1 个答案:

答案 0 :(得分:0)

$array = array('Juan', 'Pedro', 'Luis');
$data = array();
foreach($array as $a)
      $data[] = array( 'item' => $a,  'cost' => 10000, 'approved by' => 'Joe');
$this->outputCsv('document.csv', $data);

也许?