Home  >  Article  >  Backend Development  >  How to force convert string in php

How to force convert string in php

藏色散人
藏色散人Original
2020-07-08 09:22:564769browse

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.

How to force convert string in php

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn