Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php string cast vs strval function which should I use?

Tags:

string

php

What is the difference between doing a string cast and strval in php ?

  1. strval($value);

  2. (string)$value;

like image 259
Pacerier Avatar asked Sep 10 '11 13:09

Pacerier


People also ask

What is use of Strval function in PHP?

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.

How to convert a variable to a string in PHP?

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.

How to convert float to string in PHP?

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).

What is Strval?

The strval() function returns the string value of a variable.


1 Answers

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.

like image 101
CodeCaster Avatar answered Oct 17 '22 21:10

CodeCaster