DEV Community

Discussion on: CSV Challenge

Collapse
tzurbaev profile image
Timur Zurbaev

PHP:

<?php

$json = json_decode(file_get_contents('https://gist.githubusercontent.com/jorinvo/7f19ce95a9a842956358/raw/e319340c2f6691f9cc8d8cc57ed532b5093e3619/data.json'), true);

$users = array_filter($json, function (array $item) {
    return !empty($item['name']) && !empty($item['creditcard']);
});

$file = fopen(date('Ymd').'.csv', 'w+');

foreach ($users as $user) {
    fputcsv($file, [$user['name'], $user['creditcard']]);
}

fclose($file);
Collapse
simplymichael profile image
Michael Orji • Edited on

You beat me to the PHP implementation. And your solution is so elegant.