当前位置:网站首页>PHP Basics
PHP Basics
2022-07-03 11:36:00 【Jiangnan has no old friends】
PHP Basic final summary
One 、 Basic grammar
php Is a weak data type programming language , There is no need to define the type in advance , The data type of variable type and assignment related variable is not fixed
php Variable name , Start with a letter or underscore , Cannot start with a number or a special character , Case sensitive .
$a = 100;
$a = “abc”;
<?php
$a;
echo $a;
?>
Running results : Nothing out
php All integers in are signed
Can pass var_dump( change The amount 1 , Variable 1, change The amount 1, Variable 2,…) Way to display its type
When it comes to computation , The data type will be converted to high precision
There is no output
Two 、 function
Can have no return value
Introduce other . php file
<?php
//1.
require 'b.php';
//2. Introduce... Through variables
$fileName="b.php";
require $fileName;
//3.
require ('b.php');
?>
57
12
3、 ... and 、 Array
When creating an array , There is no subscript assigned to an element ,php Will automatically use the current maximum subscript value ( Integers ), add 1 As a subscript to the element
If you give the same subscript to an element , The original value will be overwritten
As the index of the array :true amount to 1,false amount to 0,null Equivalent to an empty string
Use decimals as key, Automatically truncate the decimal part
Arrays and objects cannot be used as key
// Use print_r To display the array
print_r($arr);
//var_dump Data types can be displayed when displaying arrays
var_dump($arr);
An error will be reported if the subscript is out of range when accessing the array
//php Arrays can grow dynamically
$a=array(2,3);
$a[2]=56;
echo $a[2];
Traverse :
Four 、 Classes and objects
PHP The object is passed by reference
The address of the variable you want to pass in , Use &
Member functions ( Method ) No access modifier specified , The default is public
Member variables ( attribute ) The access modifier must be specified
php Member method :
Example :
Constructors :
A class has and only has one construction method , stay php5 Although after __construct() and Class name () Can coexist , But in fact, only one can be used
The main function is to release resources , It's not destroying the object itself .
Before destroying the object , The system automatically calls the destructor method of this class
A class has at most one destructor method
Static variables can exist without creating objects , It is not a variable in the object , Is object independent , Static variables cannot be used this visit
Inherit :
When creating a subclass object , By default, the constructor of its parent class will not be called automatically
If you need to access the methods of its parent class in a subclass , have access to Parent class :: Method name or parent:: Method name To complete
If you define multiple functions with the same name ( as follows ), An error will be reported at runtime :
Methods cover :
① The number of parameters of subclass methods , Method name , It should be the same as the method of the parent class .
② A subclass method cannot reduce the access rights of a parent method
5、 ... and 、 other
1. Access database
Use mysql Extended library operations mysql Database steps :
1、 stay mysql Create a library in the database , And create tables 、 Create data
2、 stay php Enabled in file mysql
3、 Establishing a connection
4、 Select database , Set character set , And send the sql
5、 Get data from the result set , Output to page
5、 Disconnect from database , Release related resources
mysqli The extension library is mysql An improved version of the extension library ,mysqli Extended library ratio mysql Expansion libraries are more efficient , Better stability
Use mysqli Extended library operations mysql Database i step :
1、 stay mysql Create a library in the database , And create tables 、 Create data
2、 stay php Enabled in file mysqli expanded memory bank
4、 Establishing a connection
5、 Select database , send out sql
6、 From result set s Retrieve data from , Output to page
7、 Disconnect from database , Release related resources
2.MVC Development mode
MVC It's a design pattern , It forces the input of the application 、 Separate processing and output .
The application is divided into three core components : Model 、 View 、 controller . They each deal with their own tasks
M Mainly by class To do it , Used to process specific business logic
V from php To do it , Mainly used to display data
C from php To do it , Used to respond to various requests of users
MVC advantage :
Code readability 、 Expand 、 Maintenance enhancements
MVC The shortcomings of :
Increased workload 、 Not suitable for small projects 、 It is more difficult to debug the program
边栏推荐
- Qt+VTK+OCCT读取IGES/STEP模型
- Excel表格转到Word中,表格不超边缘纸张范围
- [OBS] encapsulate the basic process of OBS acquisition
- 进程与线程
- R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
- Bi skills - permission axis
- PHP server interacts with redis with a large number of close_ Wait analysis
- Analysis of EPS electric steering system
- 鸿蒙第三次培训(项目实训)
- Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
猜你喜欢
基于I2C协议的驱动开发
The world's most popular font editor FontCreator tool
MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
Application of high-precision indoor positioning technology in safety management of smart factory
一文搞懂Go语言Context
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
Cadence background color setting
Leetcode 46: full arrangement
随机推荐
基于turtlebot3实现SLAM建图及自主导航仿真
Oracle withdraw permission & create role
[vtk] source code interpretation of vtkpolydatatoimagestencil
VPP three-layer network interconnection configuration
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
鸿蒙第三次培训(项目实训)
Static library vs shared library
R语言使用gridExtra包的grid.arrange函数将lattice包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
How PHP solves the problem of high concurrency
Cadence background color setting
CSRF
uniapp scroll view 解决高度自适应、弹框滚动穿透等问题。
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
R语言使用gridExtra包的grid.arrange函数将ggplot2包的多个可视化图像横向组合起来,ncol参数自定义组合图列数、nrow参数自定义组合图行数
The world's most popular font editor FontCreator tool
Asyncio warning deprecationwarning: there is no current event loop
Cuiyusong, CTO of youzan: the core goal of Jarvis is to make products smarter and more reliable
Arctangent entropy: the latest SCI paper in July 2022
Solicitation for JGG special issue: spatio-temporal omics