PHP Basic Data types

Source: Internet
Author: User

Tag: int BSP variable body string NULL private resource number

There are eight types of data in PHP,includes 4 winning volume data types, Boolean (Boolean type) integer (integer), float/double (floating point), and string (string type)Two composite data types, array (arrays) and object (objects), two special data types: resource (Resource) and null (none, blank);
Data type Describe
Boolean (Boolean) The Boolean is the simplest data type, with only two values False (False) and true (true)
Strings (String type) A string is a sequential sequence of characters, such as Ehco "string";
Integer (integer type) An integer data type can contain integers only, and these data types may be negative or positive
Folat (floating point type) Floating-point types are used to store numbers, unlike integers where floating-point type can have decimal points
Array (arrays) A set of the same type
Object (Objects) Object is a strength, use the new command to create an object
Resource (resources) A resource is a special variable that is stored in an application of an external resource that is created by a function.
Null (blank) A special value that indicates that the variable has no value, and that the initial value of any variable is null

Boolean (Boolean)
<? PHP      $boo =false;      if ($boo= =true)         {echo "condition established";     } Else {         echo "condition is not valid";     }? >

Strings (String type)

<? PHP    $str = "String I am a string"    ; Echo $str;         Echo "</p>";     Echo ' $str ';     Echo "</p>";     Echo "$str";      Echo "</p>";     /*        The results are as follows string        I am the strings   echo1 normal output content        $str                echo2 output $str        string I am string   Echo1 Normal output content     * /

Integer (integer type)

Integers must have at least one number (0-9) integers cannot contain commas or spaces integers cannot have decimal integers plus or minus can be used to specify integers in three formats: decimal, hexadecimal (prefix 0x), or octal (prefix 0)
<?PHP$num= 1234567890;//declares a decimal integer    $num 1= 0x1234567890;//declares a hexadecimal integer    $num 2= 09212;//declare an octal integer    Echo"$num";Echo"<p>"; Echo"$num 1";Echo"<p>"; Echo"$num 2";Echo"<p>"; $x= 5985; Var_dump($x); Echo"<br>"; $x=-345;//Negative number    Var_dump($x); Echo"<br>"; $x= 0x8c;//Hexadecimal number    Var_dump($x); Echo"<br>"; $x= 047;//octal number    Var_dump($x);?>

Folat (floating point type)

 <? php      $x  =9.128  $x 1  =2342.128;     $x 2  =95.128;  var_dump  ( $x     echo  "<br>" ;  var_dump  ( $x 1     echo  "<br>" ;  var_dump  ( $x 2     echo  "<br>" ; ? 

Array (arrays)

<?PHP$num= 10; $arr=Array();//create an array with a default length of 0       Echo"Create an array of length =".Count($arr); Echo"<p>"; //assigning values to arrays using a for loop      for($i= 0;$i<$num;$i++){         Echo   $arr[$i]= "value=". "$i"; Echo"<p>"; }     $casr=Array("Chen", "Wang", "Li");//create an array using the direct assignment method     $casr[Count($casr) +1] = "Chen Lin";//the size of the array can be variable       for($i= 0;$i<Count($casr);$i++){         Echo  $casr[$i]; Echo"<p>"; }     $age=Array("Chen Lin" = "35", "Wangguo" = "19");//specifying the key and value values         Echo  $age["Chen Lin"]; ?>

Object (Objects)

classperson{Private $name; Private $age;  Public functionSetName ($name){             $this->name=$name; }      Public functionGetName () {return $this-name; }      Public functionSetage ($age){         $this->age=$age; }      Public functionGetage () {return $this-Age ; }      Public functionsay () {Echo"HI"; }}   $PR=NewPerson ();//Create an Object   $PR->sya ();//calling methods in an object?>

PHP Basic Data types

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.