Notes of the PHP variables

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Lonelyhat/article/details/90691757

 

Constants and Variables

$ A = 'asdf'; string type

$ B = 123; Integer

Automatically determine what type of variable value according to the type of assignment PHP

constant

In two ways:

The first way:

define ( "constant names", a constant value)

define("PI",3.14);

To pay attention to not need to use the $ symbol when using constant otherwise the system will think that this is variable

For special symbols can also be used

E.g:

define('-_-',smlie);

The second way:

variable name = const variable value;

Example:

const PII = 456;

const PIII = 'aaaa';

How to use constants?

display:

echo PII, PIII;

For ordinary constant, constant use echo name, constant name

For special symbolic constants

Using constant () function

echo constant('-_-');

Type conversion:

Divided into two types: cast with automatic conversion

$a='a123';

$v='123a';

Cast

(Type) variable name

echo (float)$a,(float)$v;

May also be used GetType (variable names) corresponding to the type of character string acquired
setType (variable name, type) setting the data type
different from the type of conversion is forcibly
cast variables is then copied to the copied data on the type mutual aid that remark
Setype directly to the original variable data type conversion
 

echo "<HR />";
$ VG = 'AAA'; // string
echo gettype ($ a); // should display string
// cast
echo "<br/>", (float) $ A;
echo "a", GetType ($ A), "a"; // string remains

var_dump(settype($a, 'int')),"<br/>";
echo gettype($a),$a;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Lonelyhat/article/details/90691757