


switch statement PHP random number generation, page jump, file reading and writing, file renaming, switch statement
复制代码 代码如下:
num = rand(1,5);
witch($num){
case 1:
$fp1=fopen("f1.dat",'r');
$oname = fgets($fp1);
$nname = date("YmdHis");
rename($oname,$nname);
fclose($fp1);
unlink("f1.dat");
$fp1=fopen("f1.dat",'w');
fwrite($fp1,$nname);
fclose($fp1);
header("Location: ".$nname."/1.html");
exit;
break;
case 2:
$fp2=fopen("f2.dat",'r');
$oname = fgets($fp2);
$nname = date("YmdHis");
rename($oname,$nname);
fclose($fp2);
unlink("f2.dat");
$fp2=fopen("f2.dat",'w');
fwrite
($fp2,$nname);
fclose($fp2);
header("Location: ".$nname."/2.html");
exit;
break;
case 3:
$fp3=fopen
("f3.dat",'r');
$oname = fgets($fp3);
$nname = date("YmdHis");
rename($oname,$nname);
fclose($fp3);
unlink
("f3.dat");
$fp3=fopen("f3.dat",'w');
fwrite($fp3,$nname);
fclose($fp3);
header("Location: ".$nname."/3.html");
exit;
break;
case 4:
$fp4=fopen("f4.dat",'r');
$oname = fgets($fp4);
$nname = date("YmdHis");
rename
($oname,$nname);
fclose($fp4);
unlink("f4.dat");
$fp4=fopen("f4.dat",'w');
fwrite($fp4,$nname);
fclose($fp4);
header("Location: ".$nname."/4.html");
exit;
break;
case 5:
$fp5=fopen("f5.dat",'r');
$oname = fgets($fp5);
$nname = date("YmdHis");
rename($oname,$nname);
fclose($fp5);
unlink("f5.dat");
$fp5=fopen("f5.dat",'w');
fwrite
($fp5,$nname);
fclose($fp5);
header("Location: ".$nname."/5.html");
exit;
break;
default:
break;
}
?>
刚做的一个项目中的部分代码,包含了php中随机数的产生、页面跳转、件读写、文件重命名、switch语句。
特发表出来,希望能对php学习者能够有所帮助。
以上就介绍了switch语句 php 随机数的产生、页面跳转、件读写、文件重命名、switch语句,包括了switch语句方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Conditional control structure in PHP In PHP programming, conditional control structure is a very important syntax, which allows the program to execute different code blocks based on different conditions. By using conditional control structures, we can implement the branching logic of the program and determine the execution path of the program based on the result of the condition. This article will introduce the commonly used conditional control structures in PHP, including if statements, else statements, elseif statements and switch statements, and give specific code examples. The if statement is the most basic conditional control in PHP

switch is a conditional statement that is used to calculate the value of a conditional expression to determine whether the value satisfies the case statement. If it matches, the corresponding code block will be executed. Is a common way to replace complex if-else statements.

The switch statement is a control structure commonly used in programming, which allows the program to execute different code blocks based on different condition values. It can replace multiple if-else statements to improve the readability and maintainability of the code. Although it has some limitations, under the right circumstances, using the Switch statement can make programs more concise and efficient.

Enumeration type is a data type in Java that defines a collection of constants. With the switch statement, the following functions can be achieved: Clearly represent the value range: The enumeration type is used to define a set of immutable constant values to improve code readability. Matching different enumeration constants: The switch statement allows different operations to be performed based on the enumeration constants to achieve refined control. Handling different scenarios: Through enumeration types and switch statements, various situations can be flexibly handled in actual scenarios, such as sending different email contents according to different notification types.

Switch statement usage: 1. The Switch statement can only be used for integer types, enumeration types and String types, and cannot be used for floating point types and Boolean types; 2. Each case statement must be followed by a break statement to prevent other cases from being executed. The code block without a break statement will continue to execute the code block of the next case; 3. Multiple values can be matched in one case statement, separated by commas; 4. The default code block in the Switch statement is optional, etc. wait.

Go language is an emerging programming language. It has the characteristics of efficiency, simplicity, security and concurrency, and is very suitable for use in fields such as web development, distributed systems and cloud computing. In the Go language, the switch statement is a very commonly used language structure, which can select different branches for execution based on the value of the expression. This article will introduce the basic usage and precautions of switch statements in Go language. Basic syntax: The switch statement in Go language is different from that in other programming languages.

Local variable type inference in Java10: How to use finalvar keyword in switch statement As the Java language continues to evolve, each new version introduces some new features and improvements. In Java10, one of the important new features is local variable type inference. This feature allows developers to use the var keyword instead of explicit type declarations, making the code more streamlined and readable. This article will explore how to use the finalvar switch in a switch statement.

As Golang continues to develop rapidly in recent years, it has become one of the preferred programming languages for many developers. Among Golang's many grammatical structures, the switch statement is undoubtedly a very important part. However, many developers may only use the simplest switch statement, but do not know much about the further application skills of the switch statement. This article will introduce some common application techniques of switch statements in Golang functions, in order to help readers better understand and apply s
