当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > PHP 变量

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 变量


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1537 ::
收藏到网摘: n/a

Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script.
“变量”是用来存储“值”的,如:数字(number)、字符串(string)或者函数结果(function results);它可以在脚本种重复使用。


Variables in PHP
PHP变量

All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays.
所有的PHP变量的前面都包含一个“$”符号。变量可以包含字符串、数字、数组。

Below, the PHP script assigns the string "Hello World" to a variable called $txt:
下面的案例中,我们先给“txt”附一个字符串“Hello World”,然后再显示这个“txt”变量:

<html>
<body>
<?php
$txt="Hello World";
echo $txt;
?>
</body>
</html>

To concatenate two or more variables together, use the dot (.) operator:
如果你想把两个变量合二为一,你需要使用(.)操作符,具体如下:

<html>
<body>
<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2 ;
?>
</body>
</html>

The output of the script above will be: "Hello World 1234".
上述例子输出的结果是:"Hello World 1234"


Variable Naming Rules
变量命名规则

  • A variable name must start with a letter or an underscore "_"
    一个变量的开头必须是一个字母或下划线“_”。
  • A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
    一个变量的名称只能包含字母、数字、下划线“_”(即:a-Z, 0-9 和 _)
  • A variable name should not contain spaces. If a variable name should be more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)
    变量名称不能含有空格(space)。如果一个变量中需要包含多个单词,那单词之间必须以下划线“_”连接,如:($my_string);或者使用大写字母,如:($myString)

评论 (2) 1 All

登陆 | 还没注册?