Start and end tags
- There are two common types:
<?php ?>
<script language="php"></script>
- Short mark:
<? ?>
, need to open the short_open_tag instruction of php.ini file
- ASP style tag:
<% %>
, need to open the asp_tags instruction of php.ini file
PHP Data type (9 types)
- Four types of scalar
- Boolean
- Integer
- Float
- String
- Three types of composite
- Array
- Object
- Callable (callable)
- Two special types of
- Resource (resources)
- NULL (no type)
- Pseudo type
- Mixed (mixed type)
- Number (numeric type)
- Callback (callback type, also known as callable)
- Array|object
- void
- Pseudo-Variable $ ...
- Type detection function (is_type), eg:
is_string($str)
Super Global variables
- $GLOBALS
- $_server: Saving information about headers, paths, script locations, and more
- $_request: Collecting data submitted by HTML forms
- $_post
- $_get
- $_files
- $_env
- $_cookie
- $_session
Accessing global variables in a function body
- Global $variable _name
- $GLOBALS [Variable_name]
Set constants
define(const_name, const_value, boolean)
- Const_name: Constant Name
- Const_value: Constant Value
- Boolean: Constant name case sensitive, default false sensitive, true insensitive
Create an array
array()
- Get array length
count($arr)
- Array sort: Ascending
sort()
, descendingrsort()
- Array key sort: ascending
ksort()
, descendingkrsort()
- Array value sort: ascending
asort()
, descendingarsort()
foreach Loop (for arrays only)
foreach($array as $value) {}
foreach($array as $key => $value) {}
Magic variable
__LINE__
: Current line number
__FILE__
: File full path and filename
__DIR__
: The directory where the files are located
__FUNCTION__
: function name
__METHOD__
: The method name of the class
__NAMESPACE__
: The name of the current namespace
Object oriented
- class uses the class keyword followed by the name definition
- Variables and methods can be defined within a pair of curly braces ({}) after the class name
- A variable of a class is declared with Var, and a variable can initialize a value
- A function defines the definition of a PHP function, but is accessible only through the class and its instantiated objects
PHP Beginner's mind