Trong PHP, một biến được khai báo bằng cách sử dụng dấu $ theo sau là tên biến. Ở đây, một số điểm quan trọng cần biết về các biến:$ sign followed by the variable name. Here, some important points to know about variables:
- Vì PHP là một ngôn ngữ được gõ lỏng lẻo, vì vậy chúng tôi không cần phải khai báo các loại dữ liệu của các biến. Nó tự động phân tích các giá trị và thực hiện chuyển đổi sang kiểu dữ liệu chính xác của nó.
- Sau khi khai báo một biến, nó có thể được sử dụng lại trong suốt mã.
- Toán tử gán [=] được sử dụng để gán giá trị cho một biến.
Cú pháp khai báo một biến trong PHP được đưa ra dưới đây:
Quy tắc khai báo biến PHP:
- Một biến phải bắt đầu với một dấu hiệu đô la [$], theo sau là tên biến.
- Nó chỉ có thể chứa ký tự alpha-numeric và dấu gạch dưới [A-Z, 0-9, _].
- Một tên biến phải bắt đầu bằng một chữ cái hoặc ký tự dấu gạch dưới [_].
- Một tên biến PHP không thể chứa khoảng trắng.
- Một điều cần lưu ý rằng tên biến không thể bắt đầu với một số hoặc ký hiệu đặc biệt.
- Các biến PHP có tính nhạy cảm với trường hợp, vì vậy $ name và $ name đều được coi là biến khác nhau.
Biến PHP: Khai báo chuỗi, số nguyên và float
Hãy xem ví dụ để lưu trữ các giá trị chuỗi, số nguyên và float trong các biến PHP.
Tệp: Biến1.php
Output:
string is: hello string integer is: 200 float is: 44.6
Biến PHP: tổng của hai biến
Tệp: Biến2.php
Output:
Biến PHP: Trường hợp nhạy cảm
Trong PHP, tên biến là trường hợp nhạy cảm. Vì vậy, tên biến "màu" khác với màu sắc, màu sắc, màu sắc, v.v.
Tệp: Biến3.php
Output:
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is
Biến PHP: Quy tắc
Các biến PHP phải bắt đầu bằng chữ cái hoặc dấu gạch dưới.
Biến PHP không thể bắt đầu với các số và ký hiệu đặc biệt.
Tệp: VarableValid.php
Output:
Tệp: VarableInvalid.php
Output:
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 2
PHP: Ngôn ngữ được gõ lỏng lẻo
PHP là một ngôn ngữ được đánh máy một cách lỏng lẻo, nó có nghĩa là PHP tự động chuyển đổi biến thành loại dữ liệu chính xác của nó.
Chrisnospam tại Kampmeier Dot Net
21 năm trước
Dlorre tại Yahoo Dot Com ¶
12 năm trước
Sebastopolys tại Gmail Dot Com ¶hello world.
2 tháng trước đây
Aycan yat ¶
9 năm trướcjson_decode[] or SimpleXML].
Derek tại Deperu dot com
1 năm trước
The_Tevildo tại Yahoo Dot Com ¶
I am bar.
I am bar.
I am r.
15 năm trước
Coviex tại Gmail Dot Com ¶
Omar Juvera ¶ ¶
12 năm trước
Ẩn danh ¶ ¶
Sebastopolys tại Gmail Dot Com ¶
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
This is apparent from the notes others have left, but is not explicitly stated.
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
2 tháng trước đây ¶
14 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is1
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is2
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is3
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is4
Chrisnospam tại Kampmeier Dot Net ¶
20 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is5
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is6
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is7
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is8
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is9
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 20
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 21
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
21 năm trước ¶
20 năm trước
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 23
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 24
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 25
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 26
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 27
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 28
Parse error: syntax error, unexpected '4' [T_LNUMBER], expecting variable [T_VARIABLE] or '$' in C:\wamp\www\variableinvalid.php on line 29
0
1Dlorre tại Yahoo Dot Com ¶ ¶
15 năm trước
2
3
4
Omar Juvera ¶ ¶
11 năm trước
6
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is2
8
9Mstearne tại Entermix Dot Com ¶ ¶
DNL tại au dot ru ¶
$this
0
$this
1
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Correojulian33-php tại Yahoo Dot es ¶ ¶
12 năm trước
$this
3
$this
4
$this
5
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Sebastopolys tại Gmail Dot Com ¶ ¶
13 năm trước
$this
7
Ẩn danh ¶ ¶
20 năm trước
$this
8
$this
9
0
?>
1Dlorre tại Yahoo Dot Com ¶ ¶
12 năm trước
?>
2
?>
3
?>
4
?>
5
?>
6
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Sebastopolys tại Gmail Dot Com ¶ ¶
2 tháng trước đây
?>
8
?>
9
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
0
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
1Ẩn danh ¶ ¶
2 tháng trước đây
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
2
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
3
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
4
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
5
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
6
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
7
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Aycan yat ¶ ¶
9 năm trước
It may be worth specifically noting, if variable names follow some kind of "template," they can be referenced like this:
9
0
This is apparent from the notes others have left, but is not explicitly stated.
1
This is apparent from the notes others have left, but is not explicitly stated.
2
This is apparent from the notes others have left, but is not explicitly stated.
3
This is apparent from the notes others have left, but is not explicitly stated.
4
This is apparent from the notes others have left, but is not explicitly stated.
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Derek tại Deperu dot com ¶
1 năm trước
6
This is apparent from the notes others have left, but is not explicitly stated.
7
This is apparent from the notes others have left, but is not explicitly stated.
8
This is apparent from the notes others have left, but is not explicitly stated.
This is apparent from the notes others have left, but is not explicitly stated.
9The_Tevildo tại Yahoo Dot Com ¶ ¶
15 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is00
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is01
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is02
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is03
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is04
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is05
Coviex tại Gmail Dot Com ¶ ¶
9 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is06
Derek tại Deperu dot com ¶
1 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is07
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is08
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is09
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is10
The_Tevildo tại Yahoo Dot Com ¶ ¶
21 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is11
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is12
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is13
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is14
Dlorre tại Yahoo Dot Com ¶ ¶
21 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is15
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is16
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
Dlorre tại Yahoo Dot Com ¶ ¶
14 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is18
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is19
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is20
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is21
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is22
Chrisnospam tại Kampmeier Dot Net ¶
20 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is23
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is24
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
21 năm trước ¶
4 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is26
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is27
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is28
nils dot rocine tại gmail dot com ¶ ¶
10 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is29
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is30
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is31
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0
sự vô tính tại gmail dot com ¶ ¶
14 năm trước
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is33
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is34
My car is red Notice: Undefined variable: COLOR in C:\wamp\www\variable.php on line 4 My house is Notice: Undefined variable: coLOR in C:\wamp\www\variable.php on line 5 My boat is0