Hướng dẫn php strval null - php strval null

(Php 4, Php 5, Php 7, Php 8)

Strval - Nhận giá trị chuỗi của một biếnGet string value of a variable

Sự mô tả

Strval (hỗn hợp $value): Chuỗi(mixed $value): string

Nhận giá trị chuỗi của một biến. Xem tài liệu về chuỗi để biết thêm thông tin về chuyển đổi thành chuỗi.string for more information on converting to string.

Hàm này không thực hiện định dạng trên giá trị trả về. Nếu bạn đang tìm kiếm một cách để định dạng một giá trị số dưới dạng chuỗi, vui lòng xem Sprintf () hoặc Number_format ().sprintf() or number_format().

Thông số

value

Biến đang được chuyển đổi thành một chuỗi.string.

value có thể là bất kỳ loại vô hướng hoặc một đối tượng thực hiện phương thức __tostring (). Bạn không thể sử dụng strval () trên các mảng hoặc trên các đối tượng không thực hiện phương thức __toString ().strval() on arrays or on objects that do not implement the __toString() method.

Trả về giá trị

Giá trị chuỗi của value.string value of value.

Ví dụ

Ví dụ #1 strval () Ví dụ sử dụng phương thức php ma thuật __tostring ().strval() example using PHP magic __toString() method.

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>

Xem thêm

  • boolval () - Nhận giá trị boolean của một biến
  • floatVal () - nhận giá trị float của một biến
  • intval () - Nhận giá trị số nguyên của một biến
  • setType () - Đặt loại biến
  • Sprintf () - Trả về chuỗi được định dạng
  • number_format () - Định dạng một số với hàng ngàn nhóm
  • Loại tung hứng
  • __toString()

Hayley Watson ¶

15 năm trước

As of PHP 5.2, strval() will return the string value of an object, calling its __toString() method to determine what that value is.

Đánh dấu Clements ¶

6 năm trước

Some notes about how this function has changed over time, with regards the following statement:

> You cannot use strval() on arrays or on objects that
> do not implement the __toString() method.

== Arrays ==

In PHP 5.3 and below, strval(array(1, 2, 3)) would return the string "Array" without any sort of error occurring.

value0

value1

value2

value3

value4

Tom Nicholson ¶

18 năm trước

value5

value6

value7

value8

value9

value0

value1

Kendsyder+phpnet tại gmail dot com ¶

15 năm trước

value2

value3

value4

value4

Đánh dấu Clements ¶

6 năm trước

value6

value7

value8

value9

value4

Tom Nicholson ¶

6 năm trước

value1

value2

value4

Tom Nicholson ¶

15 năm trước

value4

value5

value6

value7

value4

Đánh dấu Clements ¶

6 năm trước

value9

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
0

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
1

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
2

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
3

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
4

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
5

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
6

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
7

value4

Tom Nicholson ¶

18 năm trước

class StrValTest
{
    public function 
__toString()
    {
        return 
__CLASS__;
    }
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
9

As of PHP 5.2, strval() will return the string value of an object, calling its __toString() method to determine what that value is. 0

As of PHP 5.2, strval() will return the string value of an object, calling its __toString() method to determine what that value is. 1

As of PHP 5.2, strval() will return the string value of an object, calling its __toString() method to determine what that value is. 2

value4