PHP simple Syntax

Source: Internet
Author: User
Tags arithmetic operators scalar type null

php Simple Syntax
    1. Declaring variables $var _name= "1"; $var _num=1; $var _bool=true;
    2. var_dump "function can display the data type of our variables.

There are three key naming conventions for variable names:

    1. Variable names must begin with a letter or underscore "_", such as "$_name", "$name", "$name 2", etc.
    2. variable names can only consist of letters, numbers, and "_", and can also contain Chinese characters

3. Variable names are not allowed to contain spaces

In particular, it is important to note that variable names are case-sensitive in PHP, such as "$my _book" and "$my _book" represent two different variables

    1. use "memory_get_usage" to get the current memory consumed by PHP
data types for PHP variables

In PHP, 8 primitive types are supported, including four scalar types, two composite types, and two special types

    1. scalar Type-Boolean type. When we use echo $num _float = true;
    2. scalar type-int $num _float = 1234;
    3. scalar type-floating-point $num _float = 1.234;

4. Scalar Type-string $num _float = ' 1234 '; what happens when my string is long?

we can solve this problem by using the Heredoc structure form, first using the delimiter to represent the string (<<<), and then " <<< " then provide an identifier for God, then the string, and finally the end string to provide this identifier just use the <<< and use the same letter as the starting point. And the end of it all can be

1. Special Type-resource type

2. NULL type null (NULL): null is a null type, is insensitive to case, the null type has only one value, indicating that a variable has no value, when the assignment is null, or has not been assigned, or is unset (), in three cases the variable is considered NULL.

Constant

Constants in PHP are divided into custom constants and system constants

1. Custom constants: Define () syntax format: BOOL Define (String $constant _name, mixed $value [, $case _sensitive = True])

The first parameter, "Constant_name", is a required parameter, a constant name, or a marker, and the name of the constant is consistent with the variable, but be aware that it does not have a dollar sign. The second parameter, "value," is a required parameter, which is the value of the constant. The third parameter, "Case_sensitive", is an optional parameter, specifying whether it is case sensitive, set to true to be insensitive, and generally without specifying a third parameter, the value of the default third parameter is False.

    1. System constants:

      (1) __file__:p hp program file name. It can help us get the current file in the physical location of the server (2) __line__:P HP program file line number. It can tell us the current code in the first few lines.

      (3) Php_version: The version number of the current parser. It can tell us the current PHP parser version number, we can know in advance whether our PHP code can be parsed by the PHP parser

      (4) Php_os: Executes the current PHP version of the operating system name. It can tell us the name of the operating system used by the server, and we can optimize our code based on the operating system.

      How to determine if a constant is defined bool defined (string constants_name)

PHP arithmetic operators

comparison operators in PHP

Ternary operators in PHP

("?:") The ternary operator is also a comparison operator, for expressions (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3.

logical operators in PHP

string join operators in PHP

The string join operator is to concatenate two strings, and the string join operators provided in PHP are:

(1) Join operator (".") : It returns the string that is appended to the right argument after the left argument.

(2) Connection assignment operator (". ="): It attaches the right argument to the left argument.

the if...else of the conditional structure ...

the switch...case of the conditional structure ...

Loop structure in PHP while loop statement

Do and loop statements for the loop structure in PHP

the difference between the while and the do...while statements of the cyclic structure in PHP

whilewith theDo...whilethe difference between circular statements is that whilefirst determine whether the condition is established, after the execution cycle,Do...whileperform a task first and then decide whether to continue the loop, which meansDo...whileat least one task will be executed. When the condition isFALSEwhen the whilewill not be executed at once,Do...whilethe tasks in will execute1Times

A for loop statement for the loop structure in PHP

the Foreach Loop statement for the loop structure in PHP

PHP simple Syntax

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.