Hướng dẫn what is boolean in php - boolean trong php là gì

Đây là loại đơn giản nhất. Một bool thể hiện một giá trị sự thật. Nó có thể là true hoặc false.bool expresses a truth value. It can be either true or false.

Cú pháp

Để chỉ định một bool theo nghĩa đen, hãy sử dụng các hằng số true hoặc false. Cả hai đều không nhạy cảm trường hợp.bool literal, use the constants true or false. Both are case-insensitive.

$foo True// assign the value TRUE to $foo
?>

Thông thường, kết quả của một toán tử trả về giá trị bool được chuyển vào cấu trúc điều khiển.bool value is passed on to a control structure.

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>

Chuyển đổi thành Boolean

Để chuyển đổi rõ ràng một giá trị thành Bool, hãy sử dụng các phôi (bool) hoặc (boolean). Tuy nhiên, trong hầu hết các trường hợp, dàn diễn viên không cần thiết, vì giá trị sẽ được tự động chuyển đổi nếu toán tử, hàm hoặc cấu trúc điều khiển yêu cầu đối số bool.bool, use the (bool) or (boolean) casts. However, in most cases the cast is unnecessary, since a value will be automatically converted if an operator, function or control structure requires a bool argument.

Xem thêm Loại tung hứng.

Khi chuyển đổi sang BOOL, các giá trị sau được coi là false:bool, the following values are considered false:

  • chính boolean falsefalse itself
  • Số nguyên 0 (không)
  • Phao 0,0 và -0,0 (không)
  • Chuỗi trống và chuỗi "0"
  • một mảng có phần tử không
  • Loại NULL đặc biệt (bao gồm các biến số không đặt)
  • Các đối tượng SimplexML được tạo từ các yếu tố trống không được quy kết, tức là các phần tử không có trẻ em cũng không thuộc tính.

Mọi giá trị khác được coi là true (bao gồm mọi tài nguyên và false1).true (including any resource and false1).

Cảnh báo

false2 được coi là true, giống như bất kỳ số khác không khác (dù là âm hay dương)!true, like any other non-zero (whether negative or positive) number!

false4

Fred Koschara

9 năm trước

false5

false6

false7

false8

false9

true0

true1

true2

Mark Simon ¶

5 năm trước

true3

true4

true5

true6

true7

true2

Quản trị viên tại Eexit Dot Fr ¶

14 năm trước

true9

false0

false1

false2

Goran77 tại Fastmail Dot FM ¶

6 năm trước

false3

false4

false5

false6

true2

Terminatorul tại Gmail Dot Com ¶

15 năm trước

false8

false9

true2

Steve ¶

14 năm trước

$foo True// assign the value TRUE to $foo
?>
1

$foo True// assign the value TRUE to $foo
?>
2

$foo True// assign the value TRUE to $foo
?>
3

$foo True// assign the value TRUE to $foo
?>
4

true2

Mark Simon ¶

5 năm trước

$foo True// assign the value TRUE to $foo
?>
6

$foo True// assign the value TRUE to $foo
?>
7

$foo True// assign the value TRUE to $foo
?>
8

$foo True// assign the value TRUE to $foo
?>
9

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
0

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
1

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
2

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
3

true2

Quản trị viên tại Eexit Dot Fr ¶

15 năm trước

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
5

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
6

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
7

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
8

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
9

// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
    echo 
"The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
    echo 
"


\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
    echo 
"
\n"
;
}
?>
8

(bool)1

true2

Steve ¶

14 năm trước

(bool)3

(bool)4

(bool)5

(bool)6

Goran77 tại Fastmail Dot FM ¶

6 năm trước

(bool)7

(bool)8

true2

Terminatorul tại Gmail Dot Com ¶

9 năm trước

(boolean)0

(boolean)1

(boolean)2

(boolean)3

(boolean)4

(boolean)5

true2

Mark Simon ¶

6 năm trước

(boolean)7

(boolean)8

true2

Terminatorul tại Gmail Dot Com ¶

15 năm trước

false0

false1

true2

Steve ¶

artktec tại gmail dot com ¶

false3

false4

false5

false6

false7

false8

false9

false0

true2

Wackzingo ¶

Marklgr ¶

false2

false3

true2

7 năm trước

Geza tại Turigigeza Dot Com ¶

false5

Richie Dot Hayward tại Gmail Dot Com ¶

Fyrye tại Torntech dot com

false6

12 năm trước

14 năm trước

false7

false8

false9

false00

Goran77 tại Fastmail Dot FM ¶

15 năm trước

false01

Steve ¶

artktec tại gmail dot com ¶

false02

false03

false04

false05

Wackzingo ¶

artktec tại gmail dot com ¶

false06

false07

true2

Ví dụ Boolean là gì?

Q #2) Ví dụ Boolean là gì? Trả lời: Boolean là một loại dữ liệu nguyên thủy, có các giá trị của True True hoặc các giá trị sai. Vì vậy, bất cứ điều gì trả về giá trị của True True 'hoặc Sai Sai có thể được coi là một ví dụ Boolean. Kiểm tra một số điều kiện như là A A == B, hoặc AB AB có thể được coi là ví dụ boolean.anything that returns the value “true' or “false” can be considered as a boolean example. Checking some conditions such as “a==b” or “ab” can be considered as boolean examples.

Boolean là gì?

Trong khoa học máy tính, Boolean là một loại dữ liệu logic chỉ có thể có các giá trị đúng hoặc sai. Ví dụ, trong JavaScript, các điều kiện Boolean thường được sử dụng để quyết định phần nào của mã để thực thi (như trong các câu lệnh IF) hoặc lặp lại (chẳng hạn như trong các vòng lặp).a logical data type that can have only the values true or false . For example, in JavaScript, Boolean conditionals are often used to decide which sections of code to execute (such as in if statements) or repeat (such as in for loops).

Điều gì là đúng và sai trong PHP?

Zero là sai, khác không.Trong PHP, bạn có thể kiểm tra rõ ràng hơn bằng cách sử dụng toán tử ===.. In php you can test more explicitly using the === operator.

Ví dụ số boolean là gì?

Trong C, Boolean là một loại dữ liệu chứa hai loại giá trị, tức là, 0 và 1. Về cơ bản, giá trị loại bool đại diện cho hai loại hành vi, đúng hoặc sai.Ở đây, '0' đại diện cho giá trị sai, trong khi '1' đại diện cho giá trị thực.Trong c boolean, '0' được lưu trữ dưới dạng 0 và một số nguyên khác được lưu trữ là 1.a data type that contains two types of values, i.e., 0 and 1. Basically, the bool type value represents two types of behavior, either true or false. Here, '0' represents false value, while '1' represents true value. In C Boolean, '0' is stored as 0, and another integer is stored as 1.