Hướng dẫn what are the expressions and statements in php? - các biểu thức và câu lệnh trong php là gì?

Expressions are the most important building blocks of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value".

The most basic forms of expressions are constants and variables. When you type $a = 5, you're assigning 5 into $a. 5, obviously, has the value 5, or in other words 5 is an expression with the value of 5 [in this case, 5 is an integer constant].

After this assignment, you'd expect $a's value to be 5 as well, so if you wrote $b = $a, you'd expect it to behave just as if you wrote $b = 5. In other words, $a is an expression with the value of 5 as well. If everything works right, this is exactly what will happen.

Slightly more complex examples for expressions are functions. For instance, consider the following function:

Assuming you're familiar with the concept of functions [if you're not, take a look at the chapter about functions], you'd assume that typing $c = foo[] is essentially just like writing $c = 5, and you're right. Functions are expressions with the value of their return value. Since 50 returns 5, the value of the expression '50' is 5. Usually functions don't just return a static value but compute something.

Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports four scalar value types: int values, floating point values [float], string values and bool values [scalar values are values that you can't 'break' into smaller pieces, unlike arrays, for instance]. PHP also supports two composite [non-scalar] types: arrays and objects. Each of these value types can be assigned into variables or returned from functions.

PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, $a = 5. It's easy to see that there are two values involved here, the value of the integer constant 5, and the value of $a which is being updated to 5 as well. But the truth is that there's one additional value involved here, and that's the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that $a = 5, regardless of what it does, is an expression with the value 5. Thus, writing something like 55 is like writing 56 [a semicolon marks the end of a statement]. Since assignments are parsed in a right to left order, you can also write 57.

Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP and many other languages may be familiar with the notation of 58 and 59. These are increment and decrement operators. In PHP, like in C, there are two types of increment - pre-increment and post-increment. Both pre-increment and post-increment essentially increment the variable, and the effect on the variable is identical. The difference is with the value of the increment expression. Pre-increment, which is written 50, evaluates to the incremented value [PHP increments the variable before reading its value, thus the name 'pre-increment']. Post-increment, which is written 51 evaluates to the original value of $variable, before it was incremented [PHP increments the variable after reading its value, thus the name 'post-increment'].

A very common type of expressions are comparison expressions. These expressions evaluate to either 52 or 53. PHP supports > [bigger than], >= [bigger than or equal to], == [equal], != [not equal], < [smaller than] and 0

1

2

3

4

5

6

7

8

$b = 50

Oliver tại Hankeln-Online Dot de ¶

20 năm trước

$c = foo[]0

$c = foo[]1

$c = foo[]2

$c = foo[]3

$b = 50

Chriswarbo tại Gmail Dot Com ¶

9 năm trước

$c = foo[]5

$c = foo[]6

$c = foo[]7

$c = foo[]8

$c = foo[]9

$c = 50

$c = 51

$c = 52

$b = 50

Oliver tại Hankeln-Online Dot de ¶

9 năm trước

$c = 54

$c = 55

$b = 50

Oliver tại Hankeln-Online Dot de ¶

9 năm trước

$c = 57

$c = 58

$c = 59

500

501

$c = foo[]7

$c = foo[]8

504

505

$b = 50

Oliver tại Hankeln-Online Dot de ¶

nháy mắt716 ¶

507

15 năm trước

9 năm trước

508

509

510

$b = 50

Oliver tại Hankeln-Online Dot de ¶

nháy mắt716 ¶

512

513

514

515

516

$b = 50

15 năm trước

21 năm trước

518

519

520

521

522

523

524

525

$b = 50

Mattias tại mail dot ee ¶

20 năm trước

527

Chriswarbo tại Gmail Dot Com ¶

9 năm trước

528

529

$b = 50

Oliver tại Hankeln-Online Dot de ¶

nháy mắt716 ¶

531

532

533

$b = 50

15 năm trước

nháy mắt716 ¶

535

536

537

538

539

540

$b = 50

15 năm trước

nháy mắt716 ¶

542

543

544

15 năm trước

9 năm trước

545

546

547

$b = 50

Oliver tại Hankeln-Online Dot de ¶

9 năm trước

549

550

$b = 50

Oliver tại Hankeln-Online Dot de ¶

nháy mắt716 ¶

552

553

554

555

556

557

$b = 50

15 năm trước

nháy mắt716 ¶

559

560

561

562

563

$b = 50

Các biểu thức trong PHP là gì?

Trong PHP, các biểu thức thông thường là các chuỗi bao gồm các dấu phân cách, một mẫu và các biến đổi tùy chọn. $ exp = "/w3schools/i"; Trong ví dụ trên, / là dấu phân cách, W3Schools là mẫu đang được tìm kiếm và tôi là một công cụ sửa đổi làm cho trường hợp tìm kiếm không nhạy cảm.strings composed of delimiters, a pattern and optional modifiers. $exp = "/w3schools/i"; In the example above, / is the delimiter, w3schools is the pattern that is being searched for, and i is a modifier that makes the search case-insensitive.

Sự khác biệt giữa tuyên bố và biểu thức trong PHP là gì?

Trong thuật ngữ ngôn ngữ lập trình, một biểu thức trên mạng là sự kết hợp giữa các giá trị và hàm được trình biên dịch kết hợp và giải thích để tạo ra một giá trị mới, trái ngược với một câu lệnhbất cứ điều gì.

Hình thức biểu thức đơn giản nhất trong PHP là gì?

Trong PHP, hầu hết mọi thứ bạn viết là một biểu thức.Cách đơn giản nhất nhưng chính xác nhất để xác định biểu thức là "bất cứ điều gì có giá trị".Các dạng biểu thức cơ bản nhất là hằng số và biến.anything that has a value". The most basic forms of expressions are constants and variables.

Các biểu thức và luồng kiểm soát trong PHP là gì?

Biểu thức và luồng điều khiển trong PHP - Học PHP, MySQL, JavaScript, CSS & HTML5, Phiên bản thứ 3 [Sách] ... Các toán tử logic ..

Chủ Đề