In PHP, you can use the strval function to force conversion to a string. The syntax of this function is "string strval (mixed $var)", where the parameter var represents the variable to obtain the string value, and the result is to return var string value.
#In PHP, you can use the "strval" function to force conversion to a string.
strval() : Get the string value of the variable.
Syntax
string strval ( mixed $var )
Returns the string value of var.
var can be any scalar type. You cannot use strval() with arrays or objects.
Parameters
var The variable to get the string value.
Return value: Returns the string value of var.
PHP version: PHP 4, PHP 5, PHP 7
Example
<?php $foo = strval(123); var_dump($foo); ?>
Run result:
string(3) "123"
For more related knowledge, please Visit PHP Chinese website!
The above is the detailed content of How to force convert string in php. For more information, please follow other related articles on the PHP Chinese website!