PHP Learning One (Basic) 1th/2 page _php Tutorial

Source: Internet
Author: User
Tags null null scalar type casting type null variable scope what php
Application of the Web

When the client makes a request to the server's program, the Web server responds to the corresponding page according to the request, when the page contains PHP script, the server will give the PHP interpreter to explain the execution, the generated HTML code back to the client, the client's browser to interpret the HTML code, The page that eventually forms the page format.
What PHP can do

PHP is mainly used in three areas:
PHP parser, a Web server and a Web browser.
PHP syntax structure

The lexical structure of a programming language (lexical structure) refers to the collection of basic rules that govern how to write programs in a language.
User-defined function names or class names are case-insensitive and the variables are case-sensitive. This means that $name, $NAME, and $name are three different variables.
PHP uses semicolons to separate simple statements.
PHP comments

PHP supports C, C + + and Shell script style annotations, as follows:
Single-line Comment
/* */Multiline Comment (Note: cannot be nested)
# Script Comments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Constant

A constant is a fixed value, defined with a simple identifier, and Changshime is considered case-sensitive.
By convention constant identifiers are always capitalized.
Define () uses this function to define constants.
String (string) constants are divided into: built-in constants and custom constants.
Constants can contain only scalar data (Boolean (Boolean), Integer (Shape), float (floating point))

Built-in constants: constants provided by the PHP system that do not change in value on any page

Php_os: Displays the operating system version of the server
Php_version: Show PHP version

Some common system constants
__file__:php file name, if reference file, display reference filename
Number of lines in the __line__:php file
TRUE false: A constant that represents true or false
E_error: Indicates the most recent error in the code
E_warning: Indicates the most recent warning in the code
E_parse: Analyzing where the code has potential problems
E_notice: For something unusual but not necessarily the wrong place

Custom Constants
Use define () to define constants
Define ("MyComputer", "IBM");
Define constants: The value of the MyComputer constant is IBM
Defined ("MyComputer");
Detects if a constant is defined, returns 1 defined otherwise returns null

Variable
A dollar sign ($) in PHP followed by a variable name, which represents a variable. The name of the variable is case-sensitive
< PHP
$var = ' Bob ';
$Var = ' Joe ';
echo "$var, $Var"; Output "Bob, Joe" can output two variable names at a time
$4site = ' not yet '; illegal variable name; start a variable with a number cannot start with a number
$_4site = ' not yet '; The name of the legal variable; The underscore begins with an underscore
$i site is = ' Mansikka '; The name of the legal variable; it can be used in Chinese but not recommended.
Isset ($var)//Check whether the variable is defined
Unset ($var)//delete variable $var
Empty ($var)//Determine if the value of a variable exists
echo $var//null
>

Variable variable
A mutable variable gets the value of an ordinary variable as the variable name of the variable variable.
< PHP
$a = ' Hello '; Common variables
$ $a = ' world '; Variable variable variable with the value of a normal variable as the name of the variable variable
echo "$a ${$a}"; Output: Hello World
echo "$a $hello"; Output: Hello World
>

Constants and variables are different
The constant is preceded by a dollar sign ($);
Constants can only be defined with the Define () function, not through assignment statements;
Constants can be defined and accessed anywhere without regard to the rules of variable scope;
Once a constant is defined, it cannot be redefined or undefined;
The value of a constant can only be scalar

Data type
Four types of scalar:
Boolean Type (Boolean)
Integral type (integer)
Float (float) (floating-point number, also double)
Strings (String)
Two kinds of composite types:
Arrays (Array)
Objects (object)
Finally, there are two special types:
Resources (Resource)
NULL NULL
PHP is a very weak type of language.
In PHP, the type of a variable is usually not set by the programmer, rather, it is determined by the context at run time (that is, the value of the variable) based on the variable used.
Instance:
< PHP
$bool = TRUE; Boolean type
$STR = "Foo"; String
$int = 12; Integral type
Echo GetType ($bool); Output Boolean (GetType gets the type of the variable)
Echo GetType ($STR); Output string
>

Integral type
Integer values can be specified in decimal, hexadecimal, or octal notation, preceded by an optional symbol (-or +).
< PHP
$a = 1234; Decimal number
$a =-123; A negative number
$a = 0123; Octal number (equal to 83 in decimal)
$a = 0x1a; Hexadecimal number (equals 26 in decimal)
>

Floating point Type
Floating-point numbers (also known as floating-point numbers, double-precision, or real numbers) can be defined with any of the following syntax:
< PHP
$a = 1.234;
$a = 1.2e3;
$a = 7E-10;
>

String
String is a series of characters. In PHP, the characters and bytes, that is, a total of 256 different characters of the possibility. This also implies that PHP does not have local support for Unicode. (For a detailed explanation of the string type following a proprietary chapter)
< php $str = "Hello world!"; >

Boolean type
This is the simplest type. Boolean expresses the truth value, which can be TRUE or FALSE.
When other types are converted to a Boolean type, the following values are considered false:
Boolean value FALSE
Integer value 0 (0)
Floating-point value 0.0 (0)
Blank string and string "0"
An array with no member variables
object with no cell (PHP 4 only)
Special type NULL (including variables that have not been set)
All other values are considered TRUE (including any resources).

Array
An array is an important type of data in PHP. A scalar can hold only one data, and an array may hold multiple data.
$my =array (' 1 ', ' 2 ', ' abc ', ' d ');
Objects (object)
Object is an advanced data type that will later learn

Resources (Resource)
Resources are created and used by specialized functions.

Type casting
Type casting in PHP: Precede the variable to be converted with the target type enclosed in parentheses.
The allowable casts are:
(int), (integer)-Converted to integral type
(bool), (Boolean) – converts to Boolean type
(float), (double), (real)-converts to floating-point type
(string)-converts to a string
(array)-Convert an array
(object) – Convert to Object
< PHP
$foo = 10; $foo is an integer
$bar = (Boolean) $foo; $bar is a Boolean
>

http://www.bkjia.com/PHPjc/319106.html www.bkjia.com true http://www.bkjia.com/PHPjc/319106.html techarticle Web application When a client requests a program from the server, the Web server responds to the page according to the request, and when the page contains a PHP script, the server gives the PHP interpreter the solution ...

  • 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.