PHP is a dynamic scripting language that is more suitable for web development.
PHP supports 8 types of variable data:
Four types of scalar:
- Boolean (Boolean)
- integer(integer type)
- float(floating-point, also called double)
- String (String)
Two kinds of composite types:
- Array (arrays)
- Object (objects)
Finally, there are two special types:
- Resource(resources)
- NULL(no type)
Variables you can understand that if PHP is a person, variables are various types of clothing, the purpose of the set variable is to wear the appropriate clothes on the appropriate occasion
The focus of the variable is in the word, it is not a fixed value, we work to wear overalls, this time the variable is a Boolean, school to wear uniforms, it can be an integer, home to wear pajamas, it can be a string, a very special variable is NULL, You can understand that you don't wear anything when you are sleeping.
A compound variable is a combination of multiple types of variables that you can understand as suits, tops, trousers, gloves, ties, shoes, socks, everything, anything that can be contained.
We take a serious look at how these variables differ.
Boolean, which represents true or false, whether. Chinese Traditional Taiji, is black and white two-color, can transform each other, one side for Yang, one for the yin, the reality of men and women are also, assuming we use 1 for men, 0 for women, buy clothes as long as the judge is not a male or female money is easy to buy suitable clothes. Boolean values are very common in life, like sockets, with 0 lines and FireWire. The computer transmits data in binary. You can also understand that 0 and 1 define the range of values for shaping.
Integer: Plastic, said the easy-to-understand is an integer, the most common is the military training point to, from left to right, 1,2,3,4,5 ... in order to report, no matter how many people, the final must be an integer, this is the shape, does not contain the decimal point number.
Float: Understand the shaping, floating-point type is better understand, is with decimal values, buy things, often see a book hit special, 29.98 Yuan, 19.56 yuan, etc., which are floating point, according to the number of digits in the decimal point length, the more accurate.
String: Type, is the variable containing the text, we are small when there is a nickname, this is the time you set a variable, such as Xiao Ming, grew up, there is a name, called Li Ming, on the society, called Xiao Li, the age of Old Lee, the younger see called Li Shutong, this is a different period of your string variable.
arrays, array variables, a collection of various elements of a combination of variables, we do an ID card, a standard ID card is to have so several points, name, nationality, birth date, home address, portrait, office of the police station, ID number, etc., this is equivalent to an array of you, you can write
$you =array (' idcard ' = ' 123456198805260214 ', ' name ' = ' li Ming ', ' nationality = ' han ' ...);
When an element is called, such as a call to a name, $you [' name '] is OK
Object, which is more complex than an array, must be new before invoking the methods and properties.
We want to plant a potted flower, first to put the seeds in, watering fertilization (this is like object initialization), and so the flowers grow up, can loosen the soil, can continue watering, fertilization, until the flowers open, flowers Open is our goal, but must first sow, the process may also have fertilization, watering flowers and other necessary methods, our seeds are roses , red, which is the property of an object, is more like a dynamic process than an array.
The following is a simple assignment invocation of an object:
Class flower{
Public name;
public color;
function __construct ($name)
{
echo ' sowing ';
}
function watering ()
{
echo ' watering ';
}
}
$flower =new Flower ();
$flower->name= ' Roses ';
$flower->color= ' red ';
$flower->watering ();
Echo ' Flower's name: '. $flower->name;
echo ' Flower color: '. $flower->color;
The above 6 types of variables are commonly used,
- Resource(Resource) type need to have open handle, and open the safe need key and password, back to the introduction, with less
- null(no type), it means nothing, no declaration, no initialization, is null