tech4biz/download.php
2024-10-24 17:20:08 +05:30

38 lines
986 B
PHP

<?php
header('Content-Type: application/json');
// Function to generate random user data
function generateRandomUser() {
$firstNames = ['John', 'Jane', 'Michael', 'Emily', 'Chris', 'Jessica'];
$lastNames = ['Doe', 'Smith', 'Johnson', 'Williams', 'Brown', 'Jones'];
$user = [
'id' => uniqid(),
'first_name' => $firstNames[array_rand($firstNames)],
'last_name' => $lastNames[array_rand($lastNames)],
'email' => strtolower(uniqid() . '@example.com'),
'age' => rand(18, 65),
];
return $user;
}
// Generate an array of sample users
function generateSampleData($numUsers = 10) {
$users = [];
for ($i = 0; $i < $numUsers; $i++) {
$users[] = generateRandomUser();
}
return $users;
}
// Check if 'count' is provided in the query string
$count = isset($_GET['count']) ? (int)$_GET['count'] : 10;
$data = generateSampleData($count);
// Return the JSON response
echo json_encode($data);
?>