PHP lesson three basic data types of PHP

Source: Internet
Author: User
Tags define empty functions header sql variables string variable

Learning outline:

1.php Seven types of variables

The distinction between 2.isset and empty two functions
3. Type test
4. Automatic conversion of type

5. Type cast


Attention:

1. The method invoked in the object is called by the variable-> method name. $user 1 = new per (); $user 1->say ();
2. Change the encoding of the page:
Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");
3.header header information cannot have output



1.php Eight types of variables
Integral type
Floating-point type
Character type
Boolean type
The above four types are scalar types

Array
Object
Both of these types are composite types

Resources
Null type
Both of these types are special types



Integral type
$a = 10;
Floating-point type
$a = 10.3;
Character type
$a = "Hello world";
String links with. To link
 
  




Boolean type
$a =true;
Boolean types are generally calculated by comparison, > < >= <= = =!= = =!==
When you output a Boolean type with echo Print_r, True becomes 1,false and becomes empty
$a =true;
Var_dump ($a);
Array
Definition: When assigning multiple values to a variable
 
  ";
	Print_r ($arr);
	echo "
";?>


The value of the array:
 
  



Add to array:
 
  	



Object type
Objects are made up of two parts: Features and functions, attributes, and methods
 
  Say ();
   
? >

Resources
Null type
$a =null;
Based on the database link resources, action table:

 
  id:{$row [' id ']} ';
	echo "

name:{$row [' Name ']}

"; } ? >




The distinction between 2.isset and empty two functions
Whether the isset variable exists and does not exist:
1) No definition
2) NULL

Empty whether the variable is empty or empty:
1) # 0
2) ""
3) "0"
4) False
5) Array ()
6) NULL
7) No definition
3. Type test
Var_dump ();
1. Integral type is_int ();
2. Floating-point type is_float ();


Database connection: -->$conn = mysql_connect ("localhost", "root", "1234");
Var_dump (Is_resource ($conn));
?>

4. Automatic conversion of type
1. Integral type-> string
 
  


2. String-> integral type
$num = "1243alj";
strings are automatically converted to integral type
echo $num +1;

3. Other types of-> Boolean types
1) # 0
2) ""
3) "0"
4) False
5) Array ()
6) NULL
7) No definition
All of the above Boolean types are fake



5. Type cast
(int) $num integral type
(float) $num floating-point type
(string) $num string
(BOOL) $num Boolean

To delete a variable using:
$num = "User";
Unset ($num);
Var_dump (Isset ($num));

Single double quotation marks for strings:
1. There are no variables in the string, use single quotes
2. If you have a variable, use double quotes (single quotes can be used, but you need to use. To link)
 
  



Definition of constants:
Like a variable, but once defined, it can't be modified.
Define ("HOST", "localhost");
Define ("USER", "root");
Define ("Pass", "123");
Define ("dbname", "Test");

For example, the database configuration file, this time to use constants, and can not be modified after.

Output of constants:
Echo HOST;
Constants cannot be placed in double quotes
echo "My host is". HOST;


Operator




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.