38 lines
986 B
PHP
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);
|
|
?>
|