Data Types for PHP

Source: Internet
Author: User

Brief introduction

PHP supports 8 basic data types

Four types of scalar:

Boolen

Integer

Float (double)

String

Two kinds of composite types:

Array

Object (Objects)

Finally, there are two special types:

Resource (resources)

Null (NULL)

There are other pseudo-types:

Mixed

Number

Callback

and the pseudo-variable $ ...

Note: If you want to see the value and type of an expression, use Var_dump ().

If you just want an easy-to-read type of expression for debugging, use GetType (). To determine a type, do not use GetType () and use the Is_type function.

<?php
    $a _bool =true;//bool
    $a _str1= "foo";//string
     $a _str2= "foo";//string
    $a _int=12;//integer

    Echo GetType ($a _bool)//prints out:boolean//Be careful not to write A_bool, before adding $
    echo GetType ($a _int);//prints out : integer//note Do not write A_bool, the front to add $
    
   /*
     If This is a integer,increment it by four
     */
    if (is_int ($a _int))
 & nbsp;  {
        $a _int+=4;
        echo $a _int;
   }
   //if $a _bool is a string,print it out
    if (is_string ($a _bool))
     {
        echo "String: $a _bool";
   }
?

If you want to cast a variable to a type, you can use a cast or settype () function on it.

Data Types for PHP

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.