What is the difference between doing a string cast and strval
in php ?
strval($value)
;
(string)$value
;
The strval() function is an inbuilt function in PHP and is used to convert any scalar value (string, integer, or double) to a string. We cannot use strval() on arrays or on object, if applied then this function only returns the type name of the value being converted. Return value: This function returns a string.
Use strval() Function to Convert an Integer to a String in PHP. The function strval() is a built-in function in PHP to convert any type of variable to a string . The variable is passed as a parameter.
To convert to a string, you can use the (string) cast or the strval function; here's what this might look like: <? php $float = 1.2345; echo (string) $float, "\n"; echo strval($float), "\n"; ?> A boolean TRUE value is converted to the string "1", and the FALSE value is represented as "" (empty string).
The strval() function returns the string value of a variable.
http://www.php.net/manual/en/language.types.string.php#language.types.string.casting
A value can be converted to a string using the (string) cast or the strval() function.
Looks the same to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With