php basic syntax

php basic environment

grammatical environment

standard form

1.<?php

  this is the php code

?>

closing tag can be omitted

Case sensitivity

    mainly means that variable names are case sensitive
    . Constants are usually distinguished, but constants can also be set to be insensitive (not recommended),
    but function names are insensitive
    and keywords used in the system are not case-sensitive, such as if , else, for

Defining a variable (assignment)

Assigning a value directly to a variable is a definition

Basic rules:
1. Only use uppercase and lowercase letters, underscores (_), numbers
2, numbers cannot start with
3, and cannot have the same name as keywords in the environment (system) (such as if, for, function.....

Passing values ​​between variables

General description:
1. The value-passing method discussed here refers to: one variable to another variable
2. It is not only applicable to assignment statements, but also to other statements with the same meaning, such as: function arguments to formal parameters
3 , There are only two ways to pass by value: pass by value and pass by reference
4. In php, all variables are passed by value by default.
5. To use pass by reference, you must use the pass by reference symbol: &

 

Pass-by-value refers to copying the data value (data content) of a variable and assigning it to another variable.

$v1=1;$v2=$v1;$v3=$v1+10;

$v2++;

echo '<br/> v1=$v1,v2=$v2';

A variable variable is the name of a variable and a variable.

$v1 = "abc"; //this is a string variable whose content is the string "abc"

$abc = 10; //This is a normal variable whose content is the number 10

echo $$v1; //At this time, it is the so-called "variable variable"

 

Predefined variables are also called superglobal variables, including:

$_GET, $_POST, $_SERVER, $_REQUEST, $GLOBALS, $_COOKIE, $_SESSION, .......... (about 10)

$_GET variable(array);

The predefined array variable $_GET refers to the collection (array) of all data submitted in this way

$_POST represents the array formed by the data submitted by the page through the post method

The $_REQUEST array is not actually an independent data source, but the "total" of $_POST data and $_GET data.

Constants are used to store identifiers for data that do not change and do not want to change.

Usage form: const constant name = constant value;

two forms

1. Use the name directly

// use constant

echo CONST1;

$str2 = '<h3>'  ._c2.''</h3>''

$mianji = pi

The difference between constant variables: the
  definition form is different:
   the usage form is different: the constant does not need the $ symbol
  . The variable degree is different: the value of the constant cannot be changed, and the constant cannot be destroyed
  . use)
  different types are available: constants can only store scalar types: int, float, string, bool

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325214675&siteId=291194637