"PHP" PHP gets the first chapter

Source: Internet
Author: User

First, PHP upper and lower shell sensitive

1) All user-defined functions, classes, and keyword are sensitive.

For example, the following results are output consistent:

echo "Hello World"

Echo "Hello World"

EcHo "Hello World"

2) User-defined variables, distinguishing between uppercase and lowercase

For example, the following only has the first line to output the correct color

<?php$color= "Red"; echo "My car is". $color. "<br>"; echo "My house is". $COLOR. "<br>"; echo "My boat is". $coLOR. "<br>";? >
Second, global variables globally keyword

1) Use the Global keyword in front of the variables inside the function to access the Globals variables.

<?php$x=5; $y =10;function myTest () {  global $x, $y;  $y = $x + $y;} MyTest (); Echo $y; Output 15?

>

2) in PHP, the array named $GLOBAL [index] stores all global variables, the subscript stores all global variables, the subscript holds the variable name, the array is accessible within the function, and can be used to update global variables directly.

<?php$x=5; $y =10;function myTest () {  $GLOBALS [' y ']= $GLOBALS [' x ']+ $GLOBALS [' y ']; myTest (); Echo $y;//Output 15?

>

Third, static keywords

After the function is finished, the local variables are deleted, and sometimes the variables inside the function are remembered, using the static keyword.

<?

Phpfunction myTest () { static $x =0; echo $x; $x + +;} MyTest (); MyTest (); MyTest ();?

>


Four, the basic output method

The difference between Echo and print:

echo-can output more than one string

Print-can only output a string. And always returns 1

Tip: Echo is slightly faster than print, because it does not return whatever value.

<?

php$txt1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars =array ("Volvo", "BMW", "SAAB");p rint $txt 1;print "<br>"; Print "Study PHP at $txt 2";p rint "My car is a {$cars [0]}";? >


Five, string and integer

1) The string is a sequence of characters, for example "Hello world!".

The string can be any text within the argument. You can use single or double quotes:

2) Integer

PHP Var_dump () returns the data type and value of the variable

<?php $x = 5985;var_dump ($x); echo "<br>"; $x =-345; Negative var_dump ($x); echo "<br>"; $x = 0x8c; Hexadecimal number var_dump ($x); echo "<br>"; $x = 047; Octal number Var_dump ($x);? >

Results:

int (5985) int ( -345) int (+) int (39)


Six, array

$cars =array ("Volvo", "BMW", "SAAB"); Var_dump ($cars);


Results:

Array (3) {[0]=> string (5) "Volvo" [1]=> string (3) "BMW" [2]=> string (4) "SAAB"}

Seven, null value

NULL identifies the variable with no value, and Null is the only possible value of the data type NULL. A null value indicates whether the variable is empty and is able to empty the variable by setting the value to null.

<?php$x= "Hello world!"; $x =null;var_dump ($x);?

>



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

"PHP" PHP gets the first chapter

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.