PHP lesson three basic data types for PHP _php tutorial

Source: Internet
Author: User

PHP lesson three basic data types for PHP


Learning outline:

1.php Seven types of variables

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

5. Type casting


Attention:

1. The method called in the object is invoked through 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
The above two 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 obtained by comparison operations, > < >= <= = = = = = = = = = = = =!==
When you output a Boolean type with echo Print_r, true turns into 1,false and becomes empty
$a =true;
Var_dump ($a);
Array
Definition: When assigning multiple values to a variable
 
  ";p Rint_r ($arr); echo"
";? >


The value of the array:
 
  



To add an array:
 
  



Object type
Objects consist of two parts: Features and functions, properties and methods
 
  Say ();   ? >

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

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

name:{$row [' Name ']}

";}? >




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

Empty if the empty variable is null:
1) 0
2) ""
3) "0"
4) False
5) Array ()
6) NULL
7) No definition
3. Type testing
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 types
1. Integer-string
 
  


2. String-Integer
$num = "1243alj";
String auto-to-integer
echo $num +1;

3. Other types: Boolean type
1) 0
2) ""
3) "0"
4) False
5) Array ()
6) NULL
7) No definition
The above-mentioned Boolean types are all fake.



5. Type casting
(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 quotes for strings:
1. There is no variable in the string, just use single quotation marks
2. If there are variables, use double quotation marks (single quotation marks can also be used, but need to use. To link)
 
  



Definitions of constants:
Same as variables, but cannot be modified once defined
Define ("HOST", "localhost");
Define ("USER", "root");
Define ("PASS", "123");
Define ("DBNAME", "Test");

For example, the database configuration file, this time to use a constant, and can not be modified later.

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


Operator


http://www.bkjia.com/PHPjc/871190.html www.bkjia.com true http://www.bkjia.com/PHPjc/871190.html techarticle PHP Third lesson PHP basic Data Type Learning outline: 1.php Seven kinds of variable types 2.isset and empty two functions of the distinction 3. Type Test 4. Automatic conversion of type 5. Type casting Note: ...

  • 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.