Demand:
1, after the execution of the script, the students want to enter the English name of the whole spell, generating a random number of 01-99 between the number,
The larger the number to participate in the project practice, the number that has been caught before the next can not be the same number.
2, the first input name, the screen output information, and the name and number recorded in the file, the program can not exit
Continue waiting for other students to enter.
Implementation Code (please execute on the command line, not the Web environment):
<?php//Number Library $num = Range (1, 99);
Randomly disturbed shuffle ($num);
$filename = './user.txt ';
Open the Record file $handle = fopen ($filename, ' w ');
The sorted list of users $user = Array ();
while (true) {echo "\r\nenter your name:";
$content = Read ();
Exit Exit Script if ($content = = ' exit ') {break;
///Take out the random value $n = Array_pop ($num); Write to File fwrite ($handle, $n. $content. "
\ r \ n ");
$user [$n] = $content; Output to console echo "Hi $content, your number is". $n. "
\ r \ n ";
//close control to input stream fclose ($GLOBALS [' stdinpointer ']);
Fwrite ($handle, "\ r \ n");
Fwrite ($handle, '----------------Gorgeous separator line-----------------');
Fwrite ($handle, "\ r \ n");
Ksort ($user); foreach ($user as $k => $v) {fwrite ($handle, $k. "$v."
\ r \ n ");
//Close file fclose ($handle); /** * Get command Line Input value * @param string $length * @return string/function read ($length = ' 255 ') {if (!isset) ($GLOBALS [' Stdinpointe
R ']) {$GLOBALS [' Stdinpointer ']=fopen ("Php://stdin", "R");
$line =fgets ($GLOBALS [' Stdinpointer '], $length);
Return trim ($line);
}