How to force convert string in php

藏色散人
Release: 2023-03-02 07:24:01
Original
4770 people have browsed it

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 )
Copy after login

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);
?>
Copy after login

Run result:

string(3) "123"
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template