Php beginners and beginners
Start and end tags
- There are two common types:
<?php ?>
,<script language="php"></script>
- Short mark:
<? ?>
To open the short_open_tag command of the php. ini file
- Asp style tag:
<% %>
To open the asp_tags command of the php. ini file
Php Data Types (9 types)
- Four scalar types
- Boolean
- Integer
- Float
- String
- Three composite types
- Two special types
- Pseudo type
- Mixed (mixed type)
- Number)
- Callback (callback type, also called callable)
- Array | object
- Void
- Pseudo Variable $...
- Type detection function (is_type), eg:
is_string($str)
Super global variable
- $ GLOBALS
- $ _ SERVER: stores information about the header, path, and script location.
- $ _ REQUEST: Collect html form submitted data
- $ _ POST
- $ _ GET
- $ _ FILES
- $ _ ENV
- $ _ COOKIE
- $ _ SESSION
Access global variables in the 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: the constant name is case sensitive. The default value is false. true is not sensitive.
Create an array
array()
- Get array Length
count($arr)
- Array sorting: ascending
sort()
, Descending orderrsort()
- Sort array keys in ascending order
ksort()
, Descending orderkrsort()
- Sort array values in ascending order
asort()
, Descending orderarsort()
Foreach loop (used only for arrays)
foreach($array as $value) {}
foreach($array as $key => $value) {}
Magic variable
__LINE__
: Current row number
__FILE__
: Complete file path and file name
__DIR__
: Directory of the file
__FUNCTION__
: Function name
__METHOD__
: Class Method Name
__NAMESPACE__
: Name of the current namespace
Object-oriented
- Class Name is added after the class keyword is used
- Variables and methods can be defined in a pair of braces ({}) after the class name
- Class variables are declared using var, and variables can also be initialized.
- Function definitions are similar to php functions, but can only be accessed through the class and its instantiated objects.