Home  >  Article  >  php教程  >  php5与mysql5 web 开发技术详解-3 变量、表达式和常量

php5与mysql5 web 开发技术详解-3 变量、表达式和常量

WBOY
WBOYOriginal
2016-06-13 10:55:19865browse

1、定义、命名和分类

      分为标量变量、数组变量以及对象三种类型

 

2、打印与输出变量

      echo 语句

      printf() 函数

               实例::

               printf("%d bootles of beer on %s", 100, "the wall");

               printf("The %2\$s liks  to %1$s", "bark","dog");

      sprintf()函数

               实例:

               $formatted= fprintf("%01.2f",$var);

 

3、显示数组与对象

       print_r( 数组和变量);

       var_dump(数组\变量\对象)

       var_export(数组\变量\对象)    通过设置参数可返回变量的表示

                实例:

    $v =  var_export($a,true);  //返回php的源代码,直接用在php脚本的数组中

4、php变量支持的数据类型

      整形、双精度、字符型、布尔型

      数组、对象 、资源(Resource)

      NULL

      两种方法引用字符串: 双引号和单引号

      变量类型的获取和设置:gettype()/settype()

      数组和对象称为符合数据类型

5、变量的变量

      $var_name = 'php5';

      $$var_name = ''php5 web开发详解;

      echo $php5;

6、超级全局变量数组

      $_GET[]

      $_POST[]

      $_COOKIE[]

      $_SESSION[]

      $_ENV[]

      $_SERVER[]

      $_FILES[]

      $_REQUEST[]

      $_GLOBALS[]

7、变量操作符

       内容较多,只列出种类不具体列举。

       算术

       赋值

      字符串连接

      前置和后置加减

      引用  &   引用赋值后,变量具有相同的内存地址

      三元操作符

      比较运算

     布尔运算符  

      位操作符

      其它操作符 : 

              1、错误抑制 @  

              2、外部命令执行  

                      $out = ·dir c:·

                      print_r($out); 

                      $our = shell_exec("dir");

                      echo $out;

                      两种函数得到的结果是相同的, ·将结果置于一个数组中;shell_exec()方法将结果置于一个标量变量中

8、变量和脚步处理

 isset()

    unset()

    empty()

    is_array()\is_integer()\is_numeric()

 

9、数据转换

    将变量进行强制类型转换:

    (array)

    (bool)/(boolean)

    (int)

    (object)

    (real)/(double)/(fload)

    (string)

    其它:

    (1)intval($var):

    (2)HereDoc 

         HereDoc允许在php中嵌入一些大的文本内容,如电子邮件模板或一些html或文本内容。

         $string = 'hello';

         $output =

         HEREDOC 中\$string的值为$string

MYDOC

          echo $output;

        输出结果为:HEREDOC 中$string的值为hello

     (3)转意字符 

       \n,  \t , \\ ,\$ ,\'' 

      (4) 数值转换函数

       chr($var)  :  根据$var 的值返回对应的ASCII字符;

       ord($string)  返回字符串首字符的ASCII码值;

 

10、常量定义和魔术常量

       define("CONSTANT_NAME",常量值)

       __LINE__

       __FILE__

       __FUNCTION__

       __CLASS__

       __METHOD__

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn