Table of Contents
2.php中有关常量" >2.php中有关常量
Home Backend Development PHP Tutorial 学习PHP中自个儿遇到的不熟悉的或掌握不够牢固的知识点(待续)

学习PHP中自个儿遇到的不熟悉的或掌握不够牢固的知识点(待续)

Jun 13, 2016 am 10:52 AM
nbsp php print quot true

学习PHP中自己遇到的不熟悉的或掌握不够牢固的知识点(待续)

欢迎各位IT人事加入群:206981178,共同学习

总结的不是很好,也许有很多简单的东西对于我来说都很不熟悉,请大家勿喷

1.php中的有关变量

    变量名必须以字母或下划线 "_" 开头。

    变量名只能包含字母数字字符以及下划线。

    变量名不能包含空格。如果变量名由多个单词组成,那么应该使用下划线进行分隔(比如 $my_string),或者以大写字母开头(比如 $myString)。

   主要例子:

1

<span style="font-size:14px"><span style="background-color:rgb(255,255,255)">   $4site   = 'not yet';    // 非法变更名;以数字开头    $_4site = 'not yet';    // 合法变量名;以下划线开头   $i站点is = 'mansikka';  // 合法变量名;可以用中文</span></span>

Copy after login
php的预定义变量

      包括:$_SERVER, $_POST, $_GET, $_REQUEST,

      常用的例子:

1

<span style="font-size:14px">   $a = "PHP彦彦";   echo "通过\$GLOBALS来取变量值:".$GLOBALS['a'];       //输出:通过$GLOBALS来取变量值:PHP彦彦   echo "<br>";   echo "当前执行脚本的文件名:".$_SERVER['PHP_SELF'];        //输出:当前执行脚本的文件名:/study_php/2-3.php   echo "<br>";   echo "当前执行脚本所在的根目录:".$_SERVER['DOCUMENT_ROOT'];        //输出:当前执行脚本所在的根目录:H:/wwwroot   echo "<br>";   echo "当前执行脚本的的绝对路径:".$_SERVER['SCRIPT_FILENAME'];        //输出:当前执行脚本的的绝对路径:H:/wwwroot/study_php/2-3.php变量类型的强制转换</span><span style="font-size:14px">  PHP 中的类型强制转换和 C   中的非常像:在要转换的变量之前加上用括号括起来的目标类型。</span><span style="font-size:14px"></span><p></p><p>  允许的强制转换有:</p><p>  (int),(integer) - 转换成整型</p><p>  (bool),(boolean) - 转换成布尔型</p><p>  (float),(double),(real) - 转换成浮点型</p><p>  (string) - 转换成字符串</p><p>  (array) - 转换成数组</p><p>  (object) - 转换成对象</p><span style="font-size:14px">变量类型的判断   PHP 包括几个函数可以判断变量的类型,例如:gettype(),is_array(),is_float(),is_int(),is_object() 和 is_string()。<?php     $s = "this is a string";    $i = 9;    $arr = array(2,4,6);    is_string($s);    //返回TRUE,表示$s是一个字符串变量    is_string($i);    //返回FALSE,表示$i不是一个字符串变量    is_array($arr);   //返回TRUE,表示$arr是一个数组    is_array($s);     //返回FALSE,表示$s不是一个数组</span><pre class="brush:php;toolbar:false"><span style="font-size:14px">    //gettype()获取变量类型</span>

Copy after login
    $str = "this is a string";
    $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
";
}
?>

下班了...明天继续更新







Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

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

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

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

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

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

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

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 PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

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.

See all articles