array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.strval.php', 1 => 'strval', ), 'up' => array ( 0 => 'ref.var.php', 1 => '変数操作 関数', ), 'prev' => array ( 0 => 'function.settype.php', 1 => 'settype', ), 'next' => array ( 0 => 'function.unserialize.php', 1 => 'unserialize', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/var/functions/strval.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
strval — 変数の文字列としての値を取得する
value
の string としての値を
返します。文字列への変換の詳細については、string の
ドキュメントを参照ください。
この関数は、戻り値の書式設定は行いません。数値を文字列形式で書式設定したい場合は sprintf() あるいは number_format() を参照ください。
value
文字列に変換したい変数。
value
には、任意のスカラー型、null
および __toString()
メソッドを実装した object を使うこともできます。
strval() は配列に対して使うことはできず、
__toString()
メソッドを実装していないオブジェクトに対しても使うことはできません。
value
の文字列値を返します。
例1 マジックメソッド __toString() を使う strval() の例
<?php
class StrValTest
{
public function __toString()
{
return __CLASS__;
}
}
// 'StrValTest' と表示します
echo strval(new StrValTest);
?>