"PHP" Introduction to PHP first chapter

Source: Internet
Author: User

One, PHP is case sensitive

1) All user-defined functions, classes, and keywords are not case sensitive.

The following results are output consistent:

echo "Hello World"

Echo "Hello World"

EcHo "Hello World"

2) User-defined variables, case-sensitive

Only the first line below outputs 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 variable inside the function to access the GLOBALS variable.

<?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 the global variables, the subscript has 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 executed, 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-capable of outputting more than one string

Print-only one string is output and always returns 1

Tip: Echo is slightly faster than print because it does not return any values.

<?php$txt1= "Learn PHP"; $txt 2= "W3School.com.cn"; $cars =array ("Volvo", "BMW", "SAAB");p rint $txt 1;print "<br> ";p rint" 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, such as "Hello world!".

The string can be any text within quotation marks. You can use single or double quotation marks:

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 identity variable No value, NULL is the only possible value of the data type NULL, NULL value indicates whether the variable is empty, you can empty the variable by setting the value to null.

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


"PHP" Introduction to PHP 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.