How can the function generateLottoNumbers() be simplified for easier implementation?
The function generateLottoNumbers() can be simplified by using a loop to generate random numbers and adding them to an array. This eliminates the need for multiple if statements and makes the code more concise and easier to understand.
function generateLottoNumbers() {
$lottoNumbers = [];
for ($i = 0; $i < 6; $i++) {
$lottoNumbers[] = rand(1, 49);
}
return $lottoNumbers;
}
// Example usage
$numbers = generateLottoNumbers();
print_r($numbers);
Related Questions
- How can non-blocking sockets be implemented in PHP to prevent script blocking during fwrite operations?
- What are the steps involved in creating a separate PHP file for outputting form data in a specific format?
- How can debugging techniques be used to troubleshoot issues with conditional statements in PHP code?