本文整理汇总了PHP中League\Csv\Writer::insertAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Writer::insertAll方法的具体用法?PHP Writer::insertAll怎么用?PHP Writer::insertAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Csv\Writer
的用法示例。
在下文中一共展示了Writer::insertAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Generate a spreadsheet by transforming 3D data into 2D data.
*
* @param array $filters (optional)
* @return League\Csv\Writer
*/
public function generate(array $filters = [])
{
// Query the repository for filtered set of objects to export
$objects = $this->query($filters);
// Insert headers
$this->data->insertOne($this->getHeaders());
// Add objects as rows
if ($objects) {
// Transform a 3D object into a 2D row
$objects->transform([$this, 'transform']);
// Insert all the objects as rows
$this->data->insertAll($objects->toArray());
}
return $this->data;
}
示例2: sprintf
echo 'Error: ' . $e->getMessage();
exit;
}
echo PHP_EOL;
echo sprintf('%s open and %s closed issues pulled…', (string) count($issues['open']), (string) count($issues['closed']));
// Set up the header rows for the CSV
$toWrite = [['url', 'number', 'title', 'status', 'assignee', 'milestone', 'created_at', 'updated_at', 'body']];
$prCount = 0;
// Set up the data rows for the CSV
foreach ($issues as $states) {
foreach ($states as $issue) {
// Strip out pull requests
if (strpos($issue['html_url'], '/pull/')) {
++$prCount;
continue;
}
$assignee = $issue['assignee'] == null ? '' : $issue['assignee']['login'];
$milestone = $issue['milestone'] == null ? '' : $issue['milestone']['number'] . ': ' . $issue['milestone']['title'];
$toWrite[] = [$issue['html_url'], $issue['number'], $issue['title'], $issue['state'], $assignee, $milestone, $issue['created_at'], $issue['updated_at'], $issue['body']];
}
}
echo PHP_EOL;
echo sprintf('Stripping out %s pull requests…', (string) $prCount);
echo PHP_EOL;
echo 'Writing to CSV…';
// Write the array to the CSV file
$writer = new Writer(sprintf('%s.csv', $repo->owner . '_' . $repo->name), 'ab+');
$writer->setNullHandlingMode(Writer::NULL_AS_EMPTY);
$writer->insertAll($toWrite);
echo PHP_EOL;
echo sprintf('Done! CSV file is %s.csv', $repo->name);