当前位置:网站首页>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
边栏推荐
- Excel表格转到Word中,表格不超边缘纸张范围
- C语言二维数组
- AMS series - application startup process
- Phpcms prompt message page Jump to showmessage
- [vtk] source code interpretation of vtkpolydatatoimagestencil
- 一些常用术语
- phpcms 提示信息页面跳转showmessage
- 活动预告 | 直播行业“内卷”,以产品力拉动新的数据增长点
- Illustrated network: what is virtual router redundancy protocol VRRP?
- Web安全总结
猜你喜欢
随机推荐
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
Excel quick cross table copy and paste
银泰百货点燃城市“夜经济”
Phpcms prompt message page Jump showmessage
基于turtlebot3实现SLAM建图及自主导航仿真
How PHP solves the problem of high concurrency
Cadence background color setting
How to get started embedded future development direction of embedded
One hot code
The manuscript will be revised for release tonight. But, still stuck here, maybe what you need is a paragraph.
LeetCode 46:全排列
聊聊Flink框架中的状态管理机制
CSRF
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
Kibana~Kibana的安装和配置
C语言 AES加解密
Project management essence reading notes (6)
Touch and screen automatic rotation debugging
uniapp实现点击加载更多









