I wrote the following code for PHP type conversion: & lt ;? Php & nbsp; $ a & nbsp; = & nbsp; ''; & nbsp; & nbsp; // & nbsp; $ a & nbsp; = & nb PHP type conversion problem
I wrote the following code:
$ A = ''; // $ a = ""
Var_dump ($ a); // string (0 )""
Echo"
";
$ B = 1;
Var_dump ($ B); // int (1)
Echo"
";
$ A + = $ B;
Var_dump ($ a); // int (1). This is the problem. how can we make variable a of the string type?
Exit;
Excuse me:
What are the default transformation rules for PHP variables?
What is the most commonly used forced conversion function in development?
Php string
------ Solution --------------------
Var_dump (string) $ );
------ Solution --------------------
$ A + = $ B
Yes
$ A = $ a + $ B
Since you are performing arithmetic operations, the result is of course a numerical value rather than a string.
$ A. = $ B
Is the string
------ Solution --------------------
$ A = strval ($ );
------ Solution --------------------
$ A = intval ($ a); $ a = int ($ a), both of which are forcibly converted to an integer.
------ Solution --------------------
Var_dump (string) $ a); // method 1
Var_dump (strval ($ a); // method 2
Settype ($ a, "string"); // method 3
Var_dump ($ );
------ Solution --------------------
For more information, see The php Manual!
------ Solution --------------------
For example:
$ A = '1 ';
$ B = '2'; // $ B = 2; the same result is true for int.
$ A + = $ B; // enter 3
$ A. = $ B; // enter 12
It depends on what operations LZ is going to perform.