Variables & Data types (PHP notes)

Source: Internet
Author: User

php标记:四种php标记      1.<?php echo ‘hello‘ ;?>      2.<? echo ‘hello‘ ; ?> //短标记      3.<script language= "php" > echo ‘hello‘ ;</script>      4.<% echo ‘hello‘ ; %> //asp风格      注:2、4需要修改php.ini配置文件才可以使用,1、3可以直接使用。 php注释:      1.多行注释      /*        This script is hello world        Author: david        Date: 2010.04.01      */      2.单行注释      echo ‘hello‘ ;   //print hello      echo ‘hello‘ ;   # print hello      3.文档注释      /**       * 获取用户数据       * @param int uid       * @author david       */ 1.变量声明      变量以美元符 $ 开头,然后是变量名;      变量名由字母或下划线开头,由字母,下划线,数字组成;      变量名区分大小写;      变量名里面不能够有标点符号,空格 除了下划线以外      php是弱类型的语言,不需要事先声明变量的数据类型;      php可以不用显示的声明变量就直接使用,不过好的编码习惯:所有的变量在使用前应该进行s声明;      例: $age = 25;                   $color = ‘red‘ ;          $sum = 12 + "15" // $sum = 27 2.变量赋值      (1)值赋值:就是将赋值表达式的值复制到变量;      (2)引用赋值:php4引入了引用赋值功能,创建的变量与另一个变量引用的内容相同。          例:          $val_1 = ‘hello‘ ;          $val_2 = & $val_1 //把$val_1的内存空间地址赋值给$val_2          $val_2 = ‘goodbye‘ ;          $var_1 = ‘goodbye‘ ; 3.变量的变量    $val_1 = ‘hello‘ ;    $ $val_1 = ‘world‘ ;       echo $hello ;    echo $val_1 ;       echo ${ $val_1 }; 4.PHP的超全局变量    php提供了很多有用的预定义变量,用于提供大量与环境有关的信息。    $_SERVER 服务器变量        该全局变量包含着服务器和客户端配置及当前请求环境的有关信息        $_SERVER [ ‘SERVER_NAME‘ ]; : 当前运行脚本所在的服务器的主机名        $_SERVER [ ‘REMOTE_ADDR‘ ] : 客户端IP地址        $_SERVER [ ‘REQUEST_URI‘ ] : URL的路径部份        $_SERVER [ ‘HTTP_USER_AGENT‘ ]  :  操作系统和浏览器的有关信息    $_GET        该变量包含使用 GET 方法传递的参数的有关信息;        url: http: //localhost/test.php?id=100&page=2        $id = $_GET [ ‘id‘ ];        $page = $_GET [ ‘page‘ ];    $_POST        该变量包含使用 POST 方法传递的参数的有关信息;        html:          <form name= "reg" action= "test.php" method= "post" >            用户名:<input name= "username" type= "text" >            密码: <input name= "password" type= "password" >            <input value= "提交" type= "submit" >          </form>        php:           $username = $_POST [ ‘username‘ ];          $password = $_POST [ ‘password‘ ];    $_REQUEST        该变量记录着通过各种输入方法传递给脚本的变量,如GET,POST 但不要用这个超级全局变量因为它不安全而且速度比较慢;    $_COOKIE cookie变量数组    $_SESSION 会话变量数组    $_FILES 与上传文件有关的变量数组    $_ENV 环境变量数组    $GLOBALS 所有全局变量数组 5,常量的定义    常量是指在程序执行中无法修改的值。如 PI (3.1415926);    在脚本执行期间该值不能改变;    常量对大小写敏感,通常常量名总是大写;    常量是全局的,可以在脚本的任何地方引用;    常量分为内置常量和自定义常量;    常量使用define()函数定义;    define( ‘PI‘ , 3.1415926);    echo PI; 6.内置常量    PHP_OS           PHP所在的操作系统的名字    PHP_VERSION      当前 PHP 的版本 7.魔术常量    __LINE__ 文件中的当前行号;    __FILE__ 文件的完整路径和文件名;    __FUNCTION__ 函数名称;    __CLASS__ 类的名称;    __METHOD__ 类的方法名;  标量数据类型:字符串 数值 布尔类型 复合数据类型:数组  对象 特殊数据类型:资源  null

Variables & Data types (PHP notes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.