Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dados = array
- (
- '0' => array
- (
- 'idPaciente' => 150393,
- 'paciente' => array
- (
- 'idPaciente' => 150393,
- 'nomePaciente' => 'ANA CAROLINA TURRIONI AZEVEDO PACHECO'
- )
- ),
- '1' => array
- (
- 'idPaciente' => -1219,
- 'paciente' => array
- (
- 'idPaciente' => 150393,
- 'nomePaciente' => 'FULANO DE TAL'
- )
- )
- );
- /*
- * Aqui crio uma variavel que vai receber os campos que desejo
- */
- $armazenar_estes = null;
- foreach ($dados as $lista) {
- $armazenar_estes[] = [
- /*
- * aqui eu crio indices e passo valores para podes extrair no freach
- * do fputcsv
- */
- 'idPaciente' => $lista['idPaciente'],
- 'nomePaciente' => $lista['paciente']['nomePaciente']
- ];
- }
- $filename = 'Discador.csv';
- header("Content-type: text/csv");
- header("Content-Disposition: attachment; filename=$filename");
- $delimiter = ";";
- $output = fopen("php://output", "w");
- $header = array_keys($armazenar_estes[0]);
- fputcsv($output, $header, $delimiter);
- foreach ($armazenar_estes as $row) {
- fputcsv($output, $row, $delimiter);
- }
- fclose($output);
Advertisement
Add Comment
Please, Sign In to add comment