1. Initial knowledge of PHP
+ PHP is a cross-platform scripting language that runs on the server.
+ PHP Syntax:
<?php echo "welcome!" ;?>
PHP can put tag code in HTML like JavaScript, ECHO is the OUTPUT keyword in PHP
+ The string in PHP can be enclosed in single quotation marks or double quotes, and the string connector is "." Number and other languages are different with "+"
<?php echo ' Youyi '. The most beautiful ";?>
+ Output Multiple statements
<?php echo "Welcome to our classmates!" "; echo "Welcome". "To you!"; echo 1+2+3+4+5;?>
2. Variables
+ define variable with $ identifier: $var
+ rule: Variable names must begin with a letter or underscore "_"
Variable names can only consist of letters, numbers, and underscores "_", and may also contain kanji
Variable names cannot contain spaces, and when variable names consist of multiple words, they can be separated by underscores, or they can be named with camel-like nomenclature.
Note: variable names in PHP are case-sensitive
+ Data Types in PHP: 4 scalar types
2 Types of composite
2 Special types
The + Var_dump () method is to determine the type and length of a variable, and to output the value of the variable, if the variable has a value to lose is a variable and return data type.
+ When the value of a variable is output with a string, enclose it in double quotation marks.
+ When a string is long, you can output a string in the form of a HEREDOC structure:
<?php$string1= <<<god I have a little donkey, I never ride. One day I was on a whim, riding to the market. I had a little whip in my hand and I was proud of it. I do not know how to Hua, I fell a mud "god;echo $string 1; >
Delimiter <<< to represent strings, God is an identifier that can be arbitrarily defined by himself, and ends with the same identifier.
3. Constants
+ Define constants with define:
<?php$p = "PII";d efine ("PI", 3.14);d efine ($p, 3.14); Echo Pi;//3.14echo "<br/>"; Echo pii;//3.14?>
+ System Custom constants, can be used directly to use:
_file_: The physical location of the current file on the server
_line_: Current number of lines of code
Php_version: The version number of the current parser
Php_os: Current PHP version of the operating system name
+ Two ways to take a constant value:
1. Use the constant name directly
2. Using constant function
<?php$p= "";//define the two values of pi define ("PI1", 3.14);d efine ("PI2", 3.142);//define the precision of the value $height = "medium";//returns the constant name according to the precision, The constant is changed to a variable constant if ($height = = "Medium") { $p = "PI1";} else if ($height = = "Low") { $p = "PI2";} $r =1; $area = constant ($p) * $r * $R; echo $area;? >
+ Determines whether a constant is defined: defined function
4, operator
+ 2 assignment operator in php: "=" (copies the value of one copy to another) and "&" (reference assignment, shared memory)
$a = $b; $ A = & $b
+ comparison operator: = = = = = = = = = = = <>!=== < > <= >=
Note: equals = = in php and congruent = = = Rules and JAV Similar to
in ascript;
+ logical operators: logical AND (and, &&), logical OR (or, | |), logical XOR (XOR), logical non (!)
+ string Join operator: "." Or. = "
+ error control operator: @
+ arithmetic operators, ternary operators, and other languages like
5, language structure statement
+ two ways to iterate over an array: Take a number without removing the subscript foreach (array As $v)
take numeric and subscript foreach (array as $r = = $v)
<?php$students = Array (' ~ ' = ' to ' Fox Chong ', ' + ' = ' 林平 ', ' + ' = ' qu Yang ', ' ' ~ ' = ' ying yingying ', ' ' ~ ' = ' to ask heaven ', ' + ' = ' let me Do ', ' ~ ' and ' Chong virtual ', ' ~ ' and ' founder ', ' 2018 ' and ' Yue not group ', ' 2019 ' and ' Ning Zhong ',);//10 student number and name, with array storage/ Use the loop structure to iterate through the array, get the number and name foreach ($students as $r + $v) { echo $r. ". $v;//output (print) name echo" <br/> ";}? >
6. Arrays
+ arrays are divided into two types: indexed arrays and associative arrays
+ Array Basic operations:
<?php//indexed Array Assignment 3 ways $fruit = Array ("Apple", "pear", ' 3 ' = ' banana '), $fruit [2]= ' Persimmon ';p rint_r ($fruit);//array ([0] = [1] = > Pears [3] = = Banana [2] = persimmon)//Access index array contents echo ' <br> ';p rint_r ($fruit [' 0 ']);//Apple//Traverse array 2 ways for ($i =0; $i <4; $i + +) { echo ' <br> array '. $i. ' Value is: '. $fruit [$i];} foreach ($fruit as $k = + $v) { echo ' <br> '. $k. ' Value is: '. $v;} The basic operation of associative arrays, associative arrays and indexed arrays is the same as $fruit2 = Array (' apple ' = ' apple ', ' banana ' = ' banana ', ' pineapple ' and ' pineapple '); Echo ' <br> ';p rint_r ($fruit 2);? >
7. Functions
+ Custom Functions
+ Variable function
+ Built-in functions
+ Determine if the function exists-function_exists () (detects if the class exists-class_exists; detects if the file exists-file_exists)
8. Classes and objects
+ Methods or properties for accessing object properties in PHP
+ Methods for creating objects:
<?php class Car {public $name = ' car '; Public Function GetName () { return $this->name; }}//1. Create $car with the new keyword = new car (); Echo $car->getname (); 2. Create $className = ' Car ' by variable; $car = new $className (); echo "<br>"; echo $car->getname ();? >
+ PHP also has three types of access control keywords: private, public, protected
+ Object-oriented function is called a method, in-process function
+ keyword static method for static methods, do not need to instantiate, directly with:: Access (class Name:: Method Name)
PHP Basic Learning Notes (i)