PHP Learning with notes 1

Source: Internet
Author: User

<?php # 1. Hello World Header ("Content-type:text/html;charset=utf-8"), #解决中文乱码echo "Hello World"; # 2. Variable string What the # must be the $ symbol at the beginning of the use of this he will take this he = 1; $b = 3; $c = $a + $b; echo "\n$c"; #据说双引号里的变量名称会被替换成实际值echo ' \n$c '; #单引号还不支持转义字符!!    Echo ' <br> first newline ', Echo ' <br> second newline ';#<<< notation defines a string method #首先设置一个结束符号 #这个符号必须单独放在一个行的行首位置 #不然不能识别    #结束符必须单独一行echo <<<std<br> Hello <br> but not good std; #数组 $arr 1 = Array (' You ', ' good ');    echo "<br> $arr 1[1]";    $arr 2 = Array (0=> ' n ');    echo "<br> $arr 2[0]";    #常量 define (' Bitch ', 111); echo "<br>". Bitch. $arr 2[0]; #用. To connect the string and the variable echo "<br>". __file__; #php提供了几个常量 This is one of the #变量的作用域 # 1) function inside the scope is function # 2) Outside the function is the entire PHP but the user-defined letter    Number cannot be used # to use must use $heng = ' ha ';    function Hello () {global $heng;    echo "<br>". $heng;    } hello ();    #动态变量 #并不是我想的那样/* $a 1 = 1;    $b 1 = $a 1;    echo "<br>". $b 1;    $a 1 = 2; echo "<br>". $b 1;*/$chang _name = "trans"; $trans = ' Can see ME ';        echo "<br> $chang _name----$ $chang _name"; #php内置好多预定义的变量 must be assigned to one of our own defined #变量才能用 reference http://php.net/manual/zh/reserved.variables.php $host = $_server[' http    _host '];    echo "<br> $host"; #字符串运算符 #只有. This operation symbol cannot use the plus sign echo "<br> $a". $b ";//13 echo" <br> ".    ("$a" + "$b");//4 #连接字符 $a. = $b; #相当于 $a = $a. $b;    echo "<br>". $a; #逻辑运算 && = and, | |    = OR, Xor is true if ($a and $b) {echo ' <br> condition set ';    } #@ Mask Error message $worry = @ (5/0);    #php函数 similar to JavaScript function HelloWorld () {echo "<br><B>nihao</B>";    } HelloWorld ();    #引用传值 the same as C + +, the default parameter is $a 10 = 8;    Function Zijia (& $a) {$a + = 10;    } Zijia ($a 10);    echo "<br> $a 10";    #支持变量函数 the so-called variable function is to call the function using the variable name $func = "HelloWorld";    $func ();    #对函数的引用的就是对函数返回值的应用 function h () {return "HelloWorld";    } $aaaa = h ();    echo "<br>". $aaaa; #声明一个引用类型的函数 #发现引用函数不能直接返回一个常量 #所It can be foreseen that it returns a variable #地址 instead of copy a value directly to the Received variable function &hh () {$str = "HelloWorld";    return $str;    } $bbbb = &hh ();    echo "<br> $bbbb"; #当引用结束的时候可以通过unset () to dereference #php命名规范 #类名使用驼峰法 #类属性前面就前缀m #类的方法命名 general rule prefixes such as the is Get Set #变量使用小驼峰命名 #引用变量要有前缀r The global variable has the G prefix static variable using the s prefix #变量分割使用_ #方法, the class does not use the _ but the case is able to #php流程控制语句 and other languages as much as a foreach () #类似于java的增强for循环 #在一个 Complex PHP pages may contain multiple conditional statements, and looping statements #和函数 using {} can be cumbersome, so PHP provides another way to use ":" #代替 "{" and "end*" instead of "}" #支持endif, ENDWHILE,ENDFOR,ENDREAC    H,endswitch $s = 1;    echo "<br>";    while ($s + + <): echo "I love you <br>";    Endwhile; ?>

PHP Learning with notes 1

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.