PHP Language Basics

A, PHP tag style

1, xml style

<?php

echo " This is the xml-style tags ";

?>

2, the script style

<scrippt language="php">

echo " This is a script style ";

</script>

3, asp style

<%

echo ' This is asp style ';

%>

4, short style

<? Echo ' this is a short style ' ;?>

Two, php the Notes

1, single-line comments //

2, multi-line comments /*...*/

3, the number of documents Notes / ***** / * how many rows as the number of

4, the same style comment # //

Three, php data type

in php supports eight primitive types, 4 scalar type (Boolean boolean, integer integer, floating point type float, string string), 2 composite type (Array array, target object), 2 special kind (Resource resource, null)

Boolean boolean: The simplest type, only two values, true (true) and false (false).

Integer integer: integer data types include only whole, these data types can be positive and negative.

Float float: floating-point data type is used to store numbers, and the difference is only the integer stored decimal places. 1.0 1.2 e.g. 

String string: string type is a common character type that is a combination of some characters can represent the set of all computers. A string of numbers, letters, and symbols, one byte per character. Define a string with a single quote ', double quotes, "<<< three ways delimiter

Under the escape character string and said output here

\ N new line LF

\ R carriage CR

\ T horizontal tab HT

\\ \ backslash

$ $ Dollar sign

\' ' apostrophe

\" " Double quotes

\ [0-7] {1,3} matches a regular character octal notation \ 567

\ X [0-9A-Fa-f] {1,2} matches a regular hexadecimal character represented by \ x00

If you use a non-escape character \ so there will be \ output and character together

Array array: set the same type of a set of variables, a series of data to organize it, can be manipulated to form a whole.

Define the array syntax is as follows:

$array = array("a","b","c");
$array[key]='a';
Array Array = $ ( " A " => " Cat " , " B " => " Dog " , " C " => " Horse " ) <br> ;, keyed array (subscript) and a first key value as a is a bond Cat three cases the second embodiment of the key value is called a key <br> if neither of the first embodiment an integer from 0 to start counting the key is a key value of 0
<?php
    header("Content-Type:text/html;charset=utf-8");
    $array1 = array( 'asp','jsp','php' );
    $array2 = array( 'a'=>'asp','b'=>'jsp','c'=>'php' );
    echo '<br>';
    var_dump($array1);
    echo '<br>';
    print_r($array1);
    echo '<br>';
    print_r($array2);
    $array3 = array( '1'=>"",'2'=>"",'3'=>"",'4'=>"");
    echo '<br>';
    print_r($array3);
    $array[1]="";
    $array[2]="";
    $array[3]="";
    $array[4]="";
    echo '<br>';
    print_r($array);
    echo '<br>';
    echo $array[1];
    echo $array[2];
    echo $array[3];
    echo $array[4];
?>

 

 
 
 
 

  operation result

 Array is divided into two types: one is the numerical index array (array subscript numbers in ascending order starting from the number 0) is associated with another array (array subscript string, the string may be used to access the storage key values ​​in the array)

Sample associative array

$array4 = array("first"=>1,"second"=>2,"third"=>3,"four"=>4);
    echo $array4["third"];
    echo '<br>';
    $array4["four"]=8;
    echo $array4["four"];

 

 

  Output 38 is    

Four, PHP constants

1, constants can be understood as the same amount of value, is not to be changed anywhere in the script. A constant consists of letters, underscores, and numbers. (Tips: but the numbers can not appear at the first character)

Calls in two ways: First, direct access to the value of the constant name, the second is the use of constant () different functions can be dynamically output constant.

2, predefined constants

__FILE__ default constant, php file name

__LINE__ default number of constants php program line

PHP_VERSION built-in constants php version of the program

PHP_OS built-in operating system name constants execute php parser

TRUE is a true value of the constant

FALSE This constant is a false value

The constant NULL is a null value

3, php variable

Refers to an amount in the variable number may vary during program execution. Variable names and identifiers from $ identifier made up of letters, digits, and underscores, can not start with a number, is case sensitive.

Variable Scope

There will be scope variables when using variables.

Local variable scope where the function is

Global variables are defined outside the function for the entire scope of variables php file to use global variables inside a function will have the front plus global declarations

Static variables are declared with the static

Variable variable that is used to define a $$ variables so became variable variables (variables may generate coverage)

There are also some php custom variables

$GLOBALS $_POST $_COOKIE $_GET $_SESSION $_SERVER[******]等

4, php operator

Arithmetic Operators

+ - * /% (take the remainder if the remainder is the result of taking a negative is made negative)

That is the string operator would connect the two strings

Assignment Operators

=  $a=1

+= $a+=2 $a=$a+2

-= $a-=2 $a=$a-2

*= $a*=2 $a=$a*2

/= $a/=2 $a=$a/2

./ $a.=2 $a=$a.2

%= $a%=2 $a=$a%2

Increment and decrement operators

++ $a++   $a=$a+1

-- $a--   $a=$a-1

Bitwise operation is refers to alignment of bits after descending.

& Bitwise AND

| Bitwise or

^ Bitwise XOR

~ Bitwise

<< Bitwise left shift

>> Bitwise right shift

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<Title> bitwise </ title>
<style type="text/css">
<!--
body,td,th {
    font-size: 12px;
}
body {
    margin-left: 10px;
    margin-top: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
}
-->
</style></head>
<body>
<div align="center">
? < PHP
 $ m =. 8 ;
 $ n- = 12 is ;
 $ Mn = $ m & $ n- ;              // bit with 
echo  $ Mn "." ;
 $ Mn = $ m | $ n- ;               // bit or 
echo  $ Mn . "" ;
 $ Mn = $ m ^ $ n- ;              // bitwise XOR 
echo  $ Mn . "" ;
 $ Mn = ~ $ m ;                 // bit inversion
echo $mn ." " ;
?>
</div>
</body>
</html>

Operation results: 8124-9

Logical Operators

And && or logic true and Barbara

|| or OR logic, or wherein a is really true

a true xor exclusive or a false to true

! Non-true false logic

Comparison Operators

<(Greater than),> (less than), <= (less than or equal),> = (greater than or equal), == (equal)! = (Ranging), === (identity data type and value had equal ),! == (non-identical) 

5, php function

function is a function declaration keywords, other transmission parameters between the function parameter is passed arguments, parameters for the function definition parameters.

 

Guess you like

Origin www.cnblogs.com/stem/p/11795499.html