PHP Core Programming Knowledge points

Source: Internet
Author: User
Tags bitwise operators greatest common divisor mathematical functions type casting

First, PHP basic syntax
    1. PHP Tags: A total of four, only recommend the use of the first
    2. Statement Terminator: Semicolon
    3. Comments: Line Comments (//#) and block Comments (/* */), specification of annotations
Second, the common output statement
    1. Print
    2. Echo
    3. Var_dump
    4. Print_r
    5. Printf
Third, variable
    1. Composition of variables: variable name and variable value, variable name reference variable value
    2. Memory Composition: Heap area, stack area, user code area, global data area (variable area, constant area, static variable area), variable name in the stack area, variable value is in the variable area
    3. Basic syntax for variables: $
    4. Naming rules for variables
    5. mutable variable: The name of a variable can be replaced by a variable
    6. Basic operation of variables
      • Increment: Declare variable
      • Delete: Remove variable, unset behavior: Delete variable name space, eliminate referential relationship
      • The: Modify the value of the variable
      • Check: Gets the value of the variable, the output variable
    7. Pass-through values between variables
      • Value passing: After passing two variables exclusive occupy the respective variable name space and variable value space, complementary interference
      • Reference passing: The variable names of two variables are passed together referencing the same variable value space
    8. Pre-defined variables
      • $_server
      • $_get
      • $_post
      • $_request
    9. Other
Iv. Constants
    1. Definition of constants: Define (' name ', value, case insensitive) const constant NAME = constant value
    2. The grammatical meaning of constants: used to standardize data to ensure that data is not changed during operation
    3. To determine whether a constant exists: defined (' Constant name '), returns a Boolean value
    4. A constant naming convention, with special constant names accessed using the constant (' constant name ') method
    5. Get all constants: Get_defined_constants ()
    6. Pre-defined constants
      • Meaning
    7. MAGIC constant: The value of the constant is determined by its position
V. Data type 1. Introduction to Data types
      • program = data structure + algorithm
      • PHP Data types: Three major categories, 8 small categories
2. Binary and binary conversion
    1. Other binary conversions to decimal: Right-click to expand!
    2. Decimal Turn binary
      1. Integer
        • In addition to the second method of taking the remainder
        • Filling method
      2. Decimal: Rounding by two
    3. Decimal to other binary
      • Integer: except n remainder
      • Decimal: Multiply N Rounding
    4. octal, binary, hexadecimal direct cross-transfer
      1. Two or eight cross-transfer between
        • Eight ext. 2:1 split three (421 yards)
        • Two-turn 8:3 and a
      2. 26 or 16 cross-transfer between
        • 16 ext. 2:1 split Four
        • Two-turn 16:4 and a
      3. 86 or 16 cross-transfer between
        • Eight ext. 16: First split three, then four and one
        • 16 ext. Eight: First demolition four, repeated and a
3. Integral type Data
    1. Representation
      • Decimal
      • Octal, beginning with 0
      • Hex, starting with 0x
    2. In memory form: binary complement form stored
    3. The concept of the original code, the inverse code and the complement
4. Floating-point data
    1. Representation:
      1. Decimal form
      2. Exponential form
        • E is case insensitive
        • You have to have numbers after E.
        • Must be an integer after E
    2. In-memory form: can only be stored in the form of an exponent
    3. Comparison of floating-point numbers: Do not use floating-point numbers for comparisons because floating-point numbers lose precision
5. Boolean Data
    1. Only true and false two values, case insensitive
    2. When making logical judgments, the following values are treated as false
      • Integer 0
      • Floating point 0:0.0
      • String 0: ' 0 '
      • Empty string: ' '
      • NULL type: null
      • Empty array: Array ()
      • Objects and resource types are always true!
6. String data
    • Single quotation marks
    • Double quotes
    • Delimiter: Heredoc
    • Delimiter: Nowdoc
7. Special data types
    • Null type
    • Resource type
8. Type Conversion
    1. Type Auto-conversion

      • String type automatically converted to numeric type
      • Other types are automatically converted to Boolean type
    2. Type casting
      • Use the type cast operator () to do this!
      • Considerations when using the (array) binary casting
9. Type-dependent functions
    • Type-related functions
      • GetType
      • Settype
      • Isset
      • Empty
      • Is_type Series
Vi. operators 1. Several concepts

The concept of a. operator

B. Classification of operators

C. Precedence and binding of operators

D. Expressions and statements

2. Arithmetic operators
      • The remainder operator: The two operands are automatically converted to integers before the operation, and the symbol is determined by the dividend
      • Self-increment: + + and--in front and in the back of the difference
3. Assignment operators
      • Compound assignment operators
      • Binding of assignment operators: right associative
      • The value of the assignment expression is the value of the variable that is assigned value $ A = 100
4. String connector
      • The difference between the main and the comma
      • Before the operation, the operands of both sides are automatically converted to a string class, and then the horizontal "stitching"
5. Relational operators
      • The difference between = and = =
      • The difference between = = and = = =
6. Logical operators
      • Logic with && OR and
      • Logical OR | | OR OR
      • Logical Non!
      • Logical XOR or XOR
      • Note Short circuit operation
7. Conditional operators
      • form: Expression 1? Expression 2: Expression 3
      • There is also the behavior of short-circuit operations, which is equivalent to a simple if......else statement
8. Bitwise operators
      • Bitwise AND &
      • Bitwise OR |
      • Bitwise NON ~
      • Bitwise XOR or ^
      • Bitwise left Shift: <<, right 0
      • Bitwise RIGHT SHIFT: >>, left positive 0, negative complement 1
9. Other operators
      • New, clone, instanceof, @
Vii. Process Control 1. Introduction to Process Control
      • Three major structures: order, selection, circulation
      • Representation of the algorithm: flowchart, pseudo-code, natural language
2.if statements
      • Conditional execution: only if no else
      • If......else ...
      • If......elseif ...
3.switch statements
      • Switch statement: Once the value of the expression after the case is the same as the value of the expression after switch, the switch opens, and the closing curly brace or break statement is always encountered!
      • Difference from If statement: If statement is conditional branch, switch statement is State branch
4.while statements
      • When the loop: inside the loop body may not be executed at once
      • Hundred money to buy hundred chickens: process-oriented programming ideas-from top to bottom, gradually refinement!
5.do-while statements
      • Until the loop: inside the loop body must be executed at least once
      • Finding the greatest common divisor by the way of dividing: experience the difference between the while loop and the Do-while cycle
6.for statements
      • Use the most, because the most concise and compact
      • Execution process
      • Expression 1, expression 2, expression 3 can be omitted
7. Cyclic Interrupt Statements
      • Continue: Ends the current loop and continues the next cycle
      • Break: Ends the current entire loop
      • Hierarchy of Interrupts: default value is 1
8. Alternative syntax for Process Control statements
      • Use a colon instead of all the left curly braces.
      • The entire process Control statement ends with EndIf, Endwhile, ENDfor, Endforeach, and so on.
      • Do-while does not have this alternative syntax
9. File loading
    1. It embodies the layered design of the website to improve the reusability of the code.
    2. There are four different ways of loading, just some grammatical differences
    3. Principle of loading (process)
      • Exit PHP mode and go to HTML mode
      • Load the source code in the target file into the current location (equivalent to copying the source code into the current loaded location)
      • The source code to be loaded is pre-compiled and then executed (file loading occurs at the execution stage)
      • Enter PHP mode again
    4. Path problem at load
      • Relative path:./.. /
      • Default path: Can be configured in php.ini (include_path)
      • Absolute path: Always define Directory constants first
    5. The difference between the four modes of loading
      • Include and require
      • Include and include_once
10. Execution control of scripts
      • Die or exit
      • Sleep
viii. function 1. Definition of function 2. Composition of functions
    1. Name of function
    2. function argument list
    3. function body
3. Function call 4. Variable function

The function name can be replaced by a variable.

5. anonymous function 6. Parameters of the function
    1. Formal parameters and arguments
    2. Value passing and reference passing of parameters
    3. Default values for formal parameters
    4. Number of parameters problem
      1. Arguments more than formal parameters
      2. The argument is less than the formal parameter: there is only one correct case, when the formal parameter has a default value
      3. Functions of indeterminate parameters
        • Basic idea: Simply one does not define
        • Func_get_args () The value used to receive the argument, which is an indexed array
        • Func_get_arg () is used to get the value of an argument, and the index starts at 0.
        • Func_num_args () to get the number of arguments
    5. function body
      • Return statement
      • Multiple return statements are allowed within a function, but only one of them can be executed
      • If there are really a lot of values in a function that need to be returned, it is common practice to put the values in an array (object) and return to the array.
    6. Scope of the function
      • Global scope (global variables)
      • Local scope (local variable)
      • Hyper Global scope (pre-defined variable)
      • $GLOBALS
      • Keyword Global
7. Life cycle of variables
      • Concept: The difference from the scope of a variable
      • Static local variables: Using the keyword static
8. Recursive invocation of functions
      • Concept: The function calls itself at execution time, not as a new syntax, but as a description of an algorithm.
      • Recursive call key points: recursive exit, recursive point, write the program when the first write the recursive exit, and then write the recursive point
      • Features: Code writing is relatively simple, essentially in order to exchange space for time
10. String Functions
      • Strlen
      • Substr
      • Strtolower|strtoupper
      • Ucfirst: Capitalize first letter
      • Strrev
      • Strpos
      • Strrpos
      • Strchr|strstr
      • Strrchr
      • Trim
      • Str_replace (the character to replace, what character to replace, and which string to replace);
11. Time function
      • Time: Returns a timestamp
      • Date: Formats a timestamp in the specified format (common time placeholders: y-m-d h:i:s)
      • Strtotime
      • The microtime, plus the parameter true, returns a float-time stamp
12. Mathematical Functions
      • Abs
      • sqrt
      • Pow
      • Ceil|floor
      • Round
      • Rand|mt_rand
Nine, array
    1. Array Preliminary

      1. Array creation: Display creation, implicit creation, creation with coercion type conversions
      2. Array Access: Bracket syntax
      3. Array classification:
        1. Relationships between key values: indexed arrays and associative arrays
        2. Dimensions of arrays: one-dimensional and multidimensional arrays
    2. foreach traversal
      1. Basic syntax
      2. A few details
      3. Pointers to arrays: Reset,next, Current, key

PHP Core Programming Knowledge points

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.