Little Fat Learn PHP summary 1-----PHP Data Type ____php

Source: Internet
Author: User
Tags array definition garbage collection learn php

PHP supports 8 original types, including 4 winning types, namely Boolean (Boolean), Integer (Shape), float/double (floating-point) and string (literal), and two composite types, namely: Array (array) and object (objects) ; Two special types, namely: resource (Resource) and null. 1.1 Scalar data Types The 1.1.1 Boolean type is typically Boolean types that are applied in an expression of a condition or loop statement, in the IF condition statement, to determine if the value in the variable is true, and then output the respective information.

<?php
//output bool type and string type
$r = true;
if ($r ==true)
    echo "This is true \ n";
else
    echo "This is false \ n";
? >
Note: In PHP, not only false values are false, Boolean values are also considered false in some special cases: 0, 0.0, "0", blank string (""), only arrays with no assignment, and so on. NOTE: Dollar sign $ is a variable identifier, all variables start with a $ character, whether declaring a variable or calling a variable, you should use the $ symbol. 1.1.2 String Type (String)In PHP, there are 3 ways to define strings, single quotes ('), double quotes ("), and Qualifiers (<<<).
<?php
//output bool type and string type
$r = true;
if ($r ==true)
    echo "This is true \ n";
else
    echo "This is false \ n";

$str = ' will only see you again who you are to me. ';
echo "$str <p>";
? >
If you need to use the Swivel chair character, use single quotes only to escape the single quote "'", when using double quotes, there is a lot of attention to escape, usually using a backslash \ to escape. Integer of 1.1.3 integerThe integral type is needless to say, look at the code:
<?php
//Output shaping
$str 1 = 1234567890;
$str 2 = 0x1234567890;
$str 3 = 01234567890;
$str 4 = 01234567;
echo "Digital 1234567890 output Results:<p>";
The result of echo "decimal is: $str 1<br>";
The result of echo "hexadecimal is: $str 2<br>";
The result of Echo "octal is:";
if ($str 3 = = $str 4) {
    echo ' &str3=&str4= '. $str 3;
} else{
    Echo ' $str 3!= &str4 ';
}
? >
1.1.4 Floating-point typeFloating-point data types can be used to store numbers, or to save decimals, and in previous versions of PHP4.0, the floating-point type was labeled Double, also known as a double-precision floating-point number, but not both. There are two writing formats for floating-point numbers, one in the standard format: 3.1415 and one in the scientific notation format: 3.58E1.
<?php
//output floating-point type
echo ' <p> ';
Echo ' Pi 3 in the way of writing:<p> ';
Echo ' First: pi () = '. Pi (). ' <p> ';
Echo ' second: 3.1415926 = '. 3.1415926. ' <p> ';
Echo ' third Bell: 3145926E-11 = '. 314159265359E-11. ' <p> ';
? >

1.1.5 ArrayAn array is a set of data that is defined in the form $array = Array (key1=>value,key2=>value2), or $array = (' value1 ', ' value2 ') or $array[key] = ' Value '.
<?php
//Array definition
$array 1 = array (' Hello ', ' my ', ' name ', ' is ', ' haogaoming ');
$array 2 = Array (0=> ' php ',1=> ' is ', ' the ' => ', ' str ' => ' str ');
$array 3[0] = ' tmpname ';
? >
1.1.6 Resources (Resource)Resource types are introduced by PHP4, and when using resources, the system automatically enables the garbage collection mechanism, frees resources that are no longer in use, and avoids memory depletion, so resource types are rarely required for manual release. 1.1.7 null value (NULL)A null value, as the name suggests, indicates that no value is set for the variable, case-insensitive.

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.