学习PHP中自个儿遇到的不熟悉的或掌握不够牢固的知识点(待续)
学习PHP中自己遇到的不熟悉的或掌握不够牢固的知识点(待续)
欢迎各位IT人事加入群:206981178,共同学习
总结的不是很好,也许有很多简单的东西对于我来说都很不熟悉,请大家勿喷
1.php中的有关变量
变量名必须以字母或下划线 "_" 开头。
变量名只能包含字母数字字符以及下划线。
变量名不能包含空格。如果变量名由多个单词组成,那么应该使用下划线进行分隔(比如 $my_string),或者以大写字母开头(比如 $myString)。
主要例子:
1 |
|
包括:$_SERVER, $_POST, $_GET, $_REQUEST,
常用的例子:
1 |
|
$int = 9;
$bool = FALSE;
echo "\$str的类型是:".gettype($str);
echo "
";
echo "\$int的类型是:".gettype($int);
echo "
";
echo "\$bool的类型是:".gettype($bool);
//设置变量类型
//bool settype ( mixed var, string type )将变量 var 的类型设置成 type。
//type 的可能值为:
//“boolean” (或为“bool”,从 PHP 4.2.0 起)
//“integer” (或为“int”,从 PHP 4.2.0 起)
//“float” (只在 PHP 4.2.0 之后可以使用,对于旧版本中使用的“double”现已停用)
//“string”
//“array”
//“object”
//“null” (从 PHP 4.2.0 起)
//如果成功则返回 TRUE,失败则返回 FALSE。
?>
版权所有地址:http://blog.csdn.net/yanfangphp
变量的删除
unset() 删除指定的变量,它是一个语句,没有返回值,试图获取 unset() 的返回值将导致解析错误。
unset($var); //删除单个变量
unset($arr['elem']); //删除单个数组元素
unset($var1, $var2, $var3); //删除一个以上的变量
2.php中有关常量
php中定义常量使用 define 函数,常量我们习惯使用大写字母
一个常量一旦被定义,就不能再改变或者取消定义。
不要在常量前面加上 $ 符号
//define(ABC,"www.phpjc.cn"); //定义常量 ABC ,并赋值
//define(SIZE,100); //定义常量 SIZE
预定义常量
PHP 向它运行的任何脚本提供了大量的预定义常量。不过很多常量都是由不同的扩展库定义的,只有在加载了这些扩展库时才会出现,或者动态加载后,或者在编译时已经包括进去了。
名称 说明
__LINE__ 文件中的当前行号。
__FILE__ 文件的完整路径和文件名。
__FUNCTION__ 函数名称(这是 PHP 4.3.0 新加的)
__CLASS__ 类的名称(这是 PHP 4.3.0 新加的)
__METHOD__ 类的方法名(这是 PHP 5.0.0 新加的)
位逻辑运算符
例子 名称 结果
$a and $b And(逻辑与) TRUE,如果 $a 与 $b 都为 TRUE。
$a or $b Or(逻辑或) TRUE,如果 $a 或 $b 任一为 TRUE。
$a xor $b Xor(逻辑异或) TRUE,如果 $a 或 $b 任一为 TRUE,但不同时是。
! $a Not(逻辑非) TRUE,如果 $a 不为 TRUE。
$a && $b And(逻辑与) TRUE,如果 $a 与 $b 都为 TRUE。
$a || $b Or(逻辑或) TRUE,如果 $a 或 $b 任一为 TRUE。
这样的写法也可以正确输出(我才知道):
//输出一段文字
print PHP教程网是以PHP资源分享为主的专业网站,
力争打造成教科书式的PHP教程网。
END;
for循环中的应用方法:
/* 应用1,每个条件都有 */
for ($i = 1; $i print $i. "-";
}
/* 应用2,省略第2个表达式 */
print "
";
for ($i = 1; ; $i++) {
if ($i > 10) {
break;
}
print $i. "-";
}
print "
";
/* 应用3,省略3个表达式 */
$i = 1;
for (;;) {
if ($i > 10) {
break;
}
print $i. "-";
$i++;
}
print "
";
/* 应用4 */
for ($i = 1; $i print "
";
/* 应用5 */
for ($i = 1; $i
while循环中的应用方法:
/* 应用1 */
$i = 1;
while ($i print $i++ . "-";
}
print "
";
/* 应用2 */
$i = 1;
while ($i print $i . "-";
$i++;
endwhile;
print "
";
/* 应用3 */
$i = 1;
while ($i print $i . "-";
$i++;
if ($i>10) break;
endwhile;
//www.phpjc.cn
?>
PHP中的continoe语句
$i=0;
while ($i++ if ($i==2) { // 跳出,也就是不会输出i am 2
continue;
}
echo "i am $i
";
}
?>
下班了...明天继续更新

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
