strval()函數是PHP中的內置函數,用於將任何標量值(字符串,整數或雙精度)轉換為字符串。我們不能在數組或對象上使用strval(),如果應用,則此函數僅返回要轉換的值的類型名稱。
用法:
strval( $variable )
參數:此函數接受單個參數$variable。此參數表示我們要轉換為字符串的值
Return value:此函數返回一個字符串。通過類型轉換作為參數傳遞給它的變量的值來生成此字符串。
以下示例程序旨在說明strval()函數。
程序1::
<?php
$var_name = 32.360;
// prints the value of above variable
// as a string
echo strval($var_name);
?>
輸出:
32.36
程序2::
<?php
class geeksforgeeks
{
public function __toString()
{
// returns the class name
return __CLASS__;
}
}
// prints the name of above class as
// a string
echo strval(new geeksforgeeks);
?>
輸出:
geeksforgeeks
程序3::
<?php
// Program to illustrate the strval() function
// when an array is passed as parameter
// Input array
$arr = array(1,2,3,4,5);
// This will print only the type of value
// being converted i.e. 'Array'
echo strval($arr);
?>
參考:
http://php.net/manual/en/function.strval.php
相關用法
- p5.js hex()用法及代碼示例
- CSS url()用法及代碼示例
- PHP pi( )用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- PHP pow( )用法及代碼示例
- p5.js box()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
- p5.js value()用法及代碼示例
- d3.js d3.rgb()用法及代碼示例
- CSS rgb()用法及代碼示例
- p5.js nf()用法及代碼示例
- PHP each()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP | strval() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。