# Review Manual (1): data types

Time：2021-5-8

## Boolean type

Range:

``````true;
false;``````

transformation:

If it is false, it is true in all other cases

``var_ dump(boolval(0));         // bool(false)``

## integer

Range:

``//64 bit signed integer range, out of range converted to floating point``

Transformation:

``var_ dump(intval(true));        // int(1)``

Base:

``var_ dump(0b10); // Int (2) binary``

## float

Range: usually the maximum value is 1.8e308 and has the precision of 14 decimal digits

Transformation:

``````var_dump(floatval(true));      //float(1)
var_dump(floatval(false));     //float(0)
var_dump(floatval(NULL));      //float(0)
var_dump(floatval(123));       //float(123)
var_dump(floatval('3.14e2'));  //float(314)
var_dump(floatval('1.23'));    //float(1)
var_dump(floatval('123abc'));  //float(123)
var_dump(floatval('1a2b3c'));  //float(1)
var_dump(floatval('a1b2c3'));  //float(0)
var_dump(floatval(array(3)));  //float(1)
var_dump(floatval(array()));   //float(0)``````

Comparison:

have access to`round()`Function and then compare

``````\$a = 0.8;
\$b = 0.1 + 0.7;
var_dump(\$a);                         //float(0.8)
var_dump(\$b);                         //float(0.8)
var_dump(\$a == \$b);                   //bool(false)
var_dump(round(\$a,2) == round(\$b,2)); //bool(true)``````

## character

Range:

``\$a ='single quote ';``

Transformation:

``````var_dump(strval(true));         //string(1) "1"
var_dump(strval(false));        //string(0) ""
var_dump(strval(NULL));         //string(0) ""
var_dump(strval(1));            //string(1) "1"
var_dump(strval(3.14));         //string(4) "3.14"
var_dump(strval(array(1,2,3))); //string(5) "Array"``````

Escape:

``````\$a = 'hello:\'kitty\'';
echo \$a; //hello:'kitty'
\$b = "hello:\"kitty\"";
echo \$b; //hello:"kitty"``````

contain:

``````\$a = 'hello:"kitty"';
echo \$a; //hello:"kitty"
\$b = "hello:'kitty'";
echo \$b; //hello:'kitty'``````

Subscript:

``````\$str = 'abcdefg';
echo \$str[0]; //a``````

## array

Scope: key can be integer or string (others will be cast to these two types), value can be any type.

Coverage:

``````\$arr = array('a' => 1,'b' => 2,'a' => 3);
print_r(\$arr); //Array([a] => 3[b] => 2)``````

Indexes:

``\$arr = array(``

## object

new:

``class test{}``

Transformation:

``````\$obj1 = (object)'hello';
var_dump(\$obj1);         //object(stdClass)#1 (1) { ["scalar"]=> string(5) "hello" }
var_dump(\$obj1->scalar); //string(5) "hello"

\$obj2 = (object)110;
var_dump(\$obj2);         //object(stdClass)#2 (1) { ["scalar"]=> int(110) }
var_dump(\$obj2->scalar); //int(110)

\$obj3 = (object)array('hello',110,'name' => 'jack');
var_dump(\$obj3);        //object(stdClass)#3 (3) { ["0"]=> string(5) "hello" ["1"]=> int(110) ["name"]=> string(4) "jack" }
var_dump(\$obj3->{'0'}); //string(5) "hello"
var_dump(\$obj3->{'1'}); //int(110)
var_dump(\$obj3->name);  //string(4) "jack"

\$obj4 = (object)true;
var_dump(\$obj4);         //object(stdClass)#4 (1) { ["scalar"]=> bool(true) }
var_dump(\$obj4->scalar); //bool(true)

\$obj5 = (object)false;
var_dump(\$obj5);         //object(stdClass)#4 (1) { ["scalar"]=> bool(false) }
var_dump(\$obj5->scalar); //bool(false)

\$obj6 = (object)3.14;
var_dump(\$obj6);         //object(stdClass)#6 (1) { ["scalar"]=> float(3.14) }
var_dump(\$obj6->scalar); //float(3.14)``````

## resources

Concept: resource resource is a special variable that holds a reference to an external resource. Resources are created and used through specialized functions.

``````\$fp = fopen('error.txt','w');
var_dump(\$fp); //resource(3) of type (stream)
fclose(\$fp);``````

## NULL

Concept: a special null value means that a variable has no value. The only possible value of a null type is null.

``\$a = NULL;``

## Callable (pseudo type)

Concept: Custom callback function

``function myFunc(){``