本文整理匯總了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);