Skip to content

Instantly share code, notes, and snippets.

@millancore
Created November 25, 2024 19:32
Show Gist options
  • Select an option

  • Save millancore/565bb32cb99b4e0581ac7f03dc6aaebe to your computer and use it in GitHub Desktop.

Select an option

Save millancore/565bb32cb99b4e0581ac7f03dc6aaebe to your computer and use it in GitHub Desktop.
Faker generate dataset
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Faker\Factory;
if (file_exists('data.csv')) {
unlink('data.csv');
}
$file = fopen('data.csv', 'w');
$count = $argv[1];
if (!is_numeric($count)) {
echo 'Please provide a numeric count' . PHP_EOL;
exit(1);
}
$faker = Factory::create();
for ($i = 0; $i < $count; $i++) {
fputcsv($file, [
$faker->name,
$faker->randomElement(['M', 'F']),
$faker->numberBetween(18, 65),
]);
}
fclose($file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment