Home >Backend Development >PHP Tutorial >Detailed introduction to variable knowledge in php

Detailed introduction to variable knowledge in php

不言
不言forward
2019-03-01 13:19:141649browse

This article brings you a detailed introduction to the knowledge of variables in PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The meaning of variables

A container used to store information, the amount that can change during the running of the program

Naming rules for variables
Variables start with the $ symbol
Variable names can only start with letters or underscores
Variable names can only be letters, underscores, numbers, and cannot have special characters: commas, periods, exclamation points, spaces, etc.
Variable names are case-sensitive

Variable naming method
a, small camel case, the first letter of the first word is lowercase, and the first letter of subsequent words is capitalized. $ userName (general user Variable, function, method names)
Big camel case, the first letter of each word is capitalized. $ UserModel (generally used for class and class file naming)
b, underline naming method, $ _user_name

Type of variable (3 major categories, 8 subcategories)
a, scalar (single value)
Boolean type boolean, the value is true or false. Check whether it is a Boolean type is_boolean()
Integer type integer. The unsigned integer value is twice as large as the signed integer value. The default declaration variable is signed. Check whether it is an integer type is_integer()
Float type float (double), detect whether it is a floating point type is_float()
String type string, is_string()
b, consistent with (multi-value: multi-value type value )
Array array, detect whether it is an array is_array()
Object object, detect whether it is an object is_object()
c, special
Resources generally need to be parsed with functions
Undefined, no value or NULL

Get the variable type
Function gettype($var) to get the variable Type

Conversion of variables
a, temporary conversion, just temporarily changes the type of the variable: the first way: (int), (bool), (float), (string ), (array), (object); The second way is intval(), floatval(), strval();
b, permanent conversion, permanent conversion of the variable type.settype($var)

Scope of variables (category)
1, global variables, created outside the function, can be accessed anywhere, within the function When accessing, you need to add $global statement or use $GLOBALS['name']
2, local variable , created within the function, can only be used inside the function, the function ends Destroyed when
3, static variable , is created within the function through the keyword static, can only be used inside the function, (acts on initialization) exists after the first declaration of the function , it is not destroyed after the function ends. When the function is accessed again, the last value is used directly
4, super global variable , can be accessed in all scopes of the script; classification
a,$ GLOBALS, a global combination array containing all variables, the variable name is the key name of the array
b,$ _SERVER, an array containing information such as header, path, script location, etc.
1)$ _SERVER['HTTP_HOST'] Request the Host content in the header information to obtain the current domain name
2)$ _SERVER["SERVER_ADDR"] The IP address of the server currently running the script.
c,$ _FILES Gets information about uploaded files
1)$ _FILES[‘myFile’][‘name’] The original name of the client file.
2)$ _FILES[‘myFile’][‘type’] The MIME type of the file, which requires the browser to provide support for this information, such as "image/gif".
3)$ _FILES[‘myFile’][‘size’] The size of the uploaded file, in bytes.
4)$ _FILES['myFile']['tmp_name'] The temporary file name stored on the server after the file is uploaded
d,$ _REQUEST,#P ##OST,##_GET, #C ##OOKIE,_SESSION

The above is the detailed content of Detailed introduction to variable knowledge in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete