Xem thảo luận
Cải thiện bài viết
Lưu bài viết
ĐọcBàn luậnXem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọcunset()andusing NULL value to any variable.
Bàn luậnThe unset() function is an inbuilt function in PHP that is used to unset a specified variable. The unset() function just destroys or removes the variable from the symbol table. After the unset() applied on a variable, it’s marked for PHP garbage collection.
Syntax:
unset($variable)
- Trong bài viết này, chúng tôi sẽ thảo luận về việc giải phóng bộ nhớ bằng unset () và sử dụng giá trị null cho bất kỳ biến nào.
unSet (): hàm unset () là hàm sẵn có trong PHP được sử dụng để giải quyết một biến được chỉ định. Hàm unset () chỉ cần phá hủy hoặc xóa biến khỏi bảng ký hiệu. Sau khi unset () được áp dụng trên một biến, nó được đánh dấu cho bộ sưu tập rác PHP.The following example demonstrates the unset() function. In the following example, the $a memory is removed from the variable stack, the $a does not exist anymore after the unset action.
$ biến không được đặt
<?php
Ví dụ: Ví dụ sau đây cho thấy hàm unset (). Trong ví dụ sau, bộ nhớ $ A được xóa khỏi ngăn xếp biến, $ A không tồn tại nữa sau khi hành động không đặt.
PHP
Before unset : hello geeks
After unset :
6$a
Before unset : hello geeks
After unset :
8
$a
=
"hello geeks"
____10
Before unset : hello geeks
After unset :
2 Before unset : hello geeks
After unset :
3Before unset : hello geeks
After unset :
0$variable = null;
7 Output:
Before unset : hello geeks
After unset :
Before unset : hello geeks
After unset :
2 $variable = null;
1Before unset : hello geeks
After unset :
0null is used to empty the variable. We can create a null variable by simply assigning it to null. The memory is not freed, but NULL data is re-written or re-assigned on that particular variable.
Syntax:
$variable = null;
Example:
$ biến không được đặt
Ví dụ: Ví dụ sau đây cho thấy hàm unset (). Trong ví dụ sau, bộ nhớ $ A được xóa khỏi ngăn xếp biến, $ A không tồn tại nữa sau khi hành động không đặt.
PHP
$a
=
"hello geeks"
____10
Before unset : hello geeks
After unset :
2 Before unset : hello geeks
After unset :
3Before unset : hello geeks
After unset :
0
$a
=
"hello geeks"
____10
Before unset : hello geeks
After unset :
2 Before unset : hello geeks
After unset :
3Before unset : hello geeks
After unset :
0$variable = null;
7Output:
Before null : Hello geeks
After null :
Before unset : hello geeks
After unset :
2 $variable = null;
1Before unset : hello geeks
After unset :
0
Before unset : hello geeks
After unset :
2 $variable = null;
5Before unset : hello geeks
After unset :
0
- NULL: NULL được sử dụng để làm trống biến. Chúng ta có thể tạo một biến null bằng cách gán nó cho null. Bộ nhớ không được giải phóng, nhưng dữ liệu NULL được viết lại hoặc được chỉ định lại trên biến cụ thể đó.does not force immediate memory freeing, and it is used to free variable usage.
<?php
$a
=
Before null : Hello geeks
After null :
2Before unset : hello geeks
After unset :
0
Before unset : hello geeks
After unset :
2 Before null : Hello geeks
After null :
6Before unset : hello geeks
After unset :
0
$a
Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
0
Before unset : hello geeks
After unset :
2 Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
7Before unset : hello geeks
After unset :
0- Cái nào tốt hơn?
- chức năng unset ():
Untet () không buộc giải phóng bộ nhớ ngay lập tức và nó được sử dụng để sử dụng biến miễn phí. is better if the memory needed is less for a variable.
(Php 4, Php 5, Php 7, Php 8)
Unset - Und đặt một biến đã cho — Unset a given variable
Sự mô tả
Hành vi của unset () bên trong một hàm có thể thay đổi tùy thuộc vào loại biến bạn đang cố gắng phá hủy.unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
Nếu một biến toàn cầu hóa không được đặt () bên trong một hàm, chỉ có biến cục bộ bị phá hủy. Biến trong môi trường gọi sẽ giữ lại giá trị giống như trước khi unset () được gọi.unset() inside of a function, only the local variable is
destroyed. The variable in the calling environment will retain the same value as before unset() was called.
<?php
0
Ví dụ trên sẽ xuất ra:
Để giải quyết () một biến toàn cầu bên trong hàm, sau đó sử dụng mảng $ globals để làm như vậy:unset() a global variable inside of a function, then use the $GLOBALS array to do so:
<?php
1
Nếu một biến được truyền bởi tham chiếu là unset () bên trong một hàm, chỉ có biến cục bộ bị phá hủy. Biến trong môi trường gọi sẽ giữ lại giá trị giống như trước khi unset () được gọi.unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
<?php
2
Ví dụ trên sẽ xuất ra:
Để giải quyết () một biến toàn cầu bên trong hàm, sau đó sử dụng mảng $ globals để làm như vậy:unset() inside of a function, unset() destroys the variable only in the context of the rest of a function.
Following calls will restore the previous value of a variable.
<?php
3
Ví dụ trên sẽ xuất ra:
Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
Để giải quyết () một biến toàn cầu bên trong hàm, sau đó sử dụng mảng $ globals để làm như vậy:
Nếu một biến được truyền bởi tham chiếu là unset () bên trong một hàm, chỉ có biến cục bộ bị phá hủy. Biến trong môi trường gọi sẽ giữ lại giá trị giống như trước khi unset () được gọi. Nếu một biến tĩnh không được đặt () bên trong hàm, unSet () sẽ tiêu diệt biến chỉ trong bối cảnh phần còn lại của hàm. Các cuộc gọi sau đây sẽ khôi phục giá trị trước đó của một biến.
Thông số <?php
4
Biến không được đặt.
<?php
5
Các biến tiếp theo.
Trả về giá trịunset() example
<?php
6
Không có giá trị được trả về.
Ví dụunset() function. <?php
7 casting serves only as a
0-type cast, for completeness.
It does not alter the variable it's casting. The (unset) cast is deprecated as of PHP 7.2.0, removed as of 8.0.0.
1
Ví dụ trên sẽ xuất ra:
Để giải quyết () một biến toàn cầu bên trong hàm, sau đó sử dụng mảng $ globals để làm như vậy:
Nếu một biến được truyền bởi tham chiếu là unset () bên trong một hàm, chỉ có biến cục bộ bị phá hủy. Biến trong môi trường gọi sẽ giữ lại giá trị giống như trước khi unset () được gọi.: Because this is a language construct and not a function, it cannot be called using variable functions, or
named arguments.
Nếu một biến tĩnh không được đặt () bên trong hàm, unSet () sẽ tiêu diệt biến chỉ trong bối cảnh phần còn lại của hàm. Các cuộc gọi sau đây sẽ khôi phục giá trị trước đó của một biến.:
Thông số
Nếu một biến tĩnh không được đặt () bên trong hàm, unSet () sẽ tiêu diệt biến chỉ trong bối cảnh phần còn lại của hàm. Các cuộc gọi sau đây sẽ khôi phục giá trị trước đó của một biến.:
Thông số
Nếu một biến tĩnh không được đặt () bên trong hàm, unSet () sẽ tiêu diệt biến chỉ trong bối cảnh phần còn lại của hàm. Các cuộc gọi sau đây sẽ khôi phục giá trị trước đó của một biến.:
Thông sốunset() on inaccessible object properties, the __unset() overloading method will be called, if declared.
<?php
4
- Biến không được đặt.
-
<?php
5 - __unset()
- Các biến tiếp theo.
- Trả về giá trị
Không có giá trị được trả về. ¶
Ví dụ
3
4
5
6
7
Ví dụ #1 unset () ví dụ ¶
Ví dụ #2 sử dụng <?php
7 đúc
8
9
$a
0
$a
1
$a
2 <?php
7 đúc thường bị nhầm lẫn với hàm unset (). <?php
7 Đúc chỉ phục vụ như một diễn viên ____ 60 loại, cho sự hoàn chỉnh. Nó không làm thay đổi biến mà nó đúc. Diễn viên (UnST) được không dùng nữa là Php 7.2.0, được loại bỏ là 8.0.0. ¶
Ví dụ #2 sử dụng <?php
7 đúc
$a
3
$a
4
7 <?php
7 đúc thường bị nhầm lẫn với hàm unset (). <?php
7 Đúc chỉ phục vụ như một diễn viên ____ 60 loại, cho sự hoàn chỉnh. Nó không làm thay đổi biến mà nó đúc. Diễn viên (UnST) được không dùng nữa là Php 7.2.0, được loại bỏ là 8.0.0. ¶
Ghi chú
$a
6
$a
7
$a
8
$a
9 Lưu ý: Bởi vì đây là một cấu trúc ngôn ngữ và không phải là một hàm, nó không thể được gọi là sử dụng các hàm biến hoặc các đối số được đặt tên. ¶
17 năm trước
=
0
=
1
7 Ghi chú: ¶
Có thể giải phóng các thuộc tính đối tượng có thể nhìn thấy trong bối cảnh hiện tại.
=
3
=
4
=
5
=
6
=
7
7 Không thể tháo gỡ
2 bên trong một phương thức đối tượng. ¶
15 năm trước
=
9
"hello geeks"
0
"hello geeks"
1
"hello geeks"
2
7 Khi sử dụng unset () trên các thuộc tính đối tượng không thể truy cập, phương thức quá tải __unset () sẽ được gọi, nếu được khai báo. ¶
Có thể giải phóng các thuộc tính đối tượng có thể nhìn thấy trong bối cảnh hiện tại.
"hello geeks"
4
"hello geeks"
5
"hello geeks"
6
"hello geeks"
7
Không thể tháo gỡ
2 bên trong một phương thức đối tượng. ¶
Khi sử dụng unset () trên các thuộc tính đối tượng không thể truy cập, phương thức quá tải __unset () sẽ được gọi, nếu được khai báo.
"hello geeks"
8
"hello geeks"
9
Before unset : hello geeks
After unset :
00Before unset : hello geeks
After unset :
01Before unset : hello geeks
After unset :
02Before unset : hello geeks
After unset :
03Before unset : hello geeks
After unset :
04Before unset : hello geeks
After unset :
05Before unset : hello geeks
After unset :
06Before unset : hello geeks
After unset :
07Before unset : hello geeks
After unset :
08Before unset : hello geeks
After unset :
09Before unset : hello geeks
After unset :
10Before unset : hello geeks
After unset :
11Before unset : hello geeks
After unset :
12Before unset : hello geeks
After unset :
13
7 Xem thêm ¶
17 năm trước
Before unset : hello geeks
After unset :
15Before unset : hello geeks
After unset :
16Before unset : hello geeks
After unset :
17Before unset : hello geeks
After unset :
18 ISSET () - Xác định xem một biến được khai báo và khác với NULL ¶
12 năm trước
Before unset : hello geeks
After unset :
19Before unset : hello geeks
After unset :
20Before unset : hello geeks
After unset :
21Before unset : hello geeks
After unset :
22Before unset : hello geeks
After unset :
23 Tecdoc tại Ukr Dot Net ¶ ¶
5 tháng trước
Before unset : hello geeks
After unset :
24Ẩn danh ¶ ¶
15 năm trước
Before unset : hello geeks
After unset :
25Before unset : hello geeks
After unset :
26Before unset : hello geeks
After unset :
21Before unset : hello geeks
After unset :
28Before unset : hello geeks
After unset :
29 Lion_Cat tại Mail Ru ¶ ¶
13 năm trước
Before unset : hello geeks
After unset :
30Before unset : hello geeks
After unset :
31Before unset : hello geeks
After unset :
32Before unset : hello geeks
After unset :
33Before unset : hello geeks
After unset :
34Before unset : hello geeks
After unset :
35
7 Dan at--nospam-- cubeland dot co dot uk ¶ ¶
17 năm trước
Before unset : hello geeks
After unset :
37Before unset : hello geeks
After unset :
38Before unset : hello geeks
After unset :
17Before unset : hello geeks
After unset :
40 Thorry tại Thorry Dot Net ¶
18 năm trước
Before unset : hello geeks
After unset :
41Before unset : hello geeks
After unset :
42Before unset : hello geeks
After unset :
43Before unset : hello geeks
After unset :
44Before unset : hello geeks
After unset :
45Before unset : hello geeks
After unset :
46Before unset : hello geeks
After unset :
47Before unset : hello geeks
After unset :
48Before unset : hello geeks
After unset :
49Before unset : hello geeks
After unset :
50Before unset : hello geeks
After unset :
51Before unset : hello geeks
After unset :
52Before unset : hello geeks
After unset :
53Before unset : hello geeks
After unset :
54Before unset : hello geeks
After unset :
55Before unset : hello geeks
After unset :
56
7
Pauljamescampbell tại Gmail Dot Com ¶ ¶
14 năm trước
Before unset : hello geeks
After unset :
58Before unset : hello geeks
After unset :
59
7 Ẩn danh ¶ ¶
12 năm trước
Before unset : hello geeks
After unset :
61Before unset : hello geeks
After unset :
62
7 15 năm trước ¶
18 năm trước
Before unset : hello geeks
After unset :
64Before unset : hello geeks
After unset :
65Before unset : hello geeks
After unset :
66
7
Pauljamescampbell tại Gmail Dot Com ¶ ¶
12 năm trước
Before unset : hello geeks
After unset :
68Before unset : hello geeks
After unset :
69Before unset : hello geeks
After unset :
70Before unset : hello geeks
After unset :
71
7 14 năm trước ¶
Warheog tại Warhog Dot Net
Before unset : hello geeks
After unset :
73Before unset : hello geeks
After unset :
74Before unset : hello geeks
After unset :
75Before unset : hello geeks
After unset :
76
7 Edouard Dot Berge tại Gmail Dot Com ¶ ¶
15 năm trước
Before unset : hello geeks
After unset :
78Before unset : hello geeks
After unset :
79
7
Lion_Cat tại Mail Ru ¶ ¶
14 năm trước
Before unset : hello geeks
After unset :
81Before unset : hello geeks
After unset :
82Before unset : hello geeks
After unset :
83Before unset : hello geeks
After unset :
84Before unset : hello geeks
After unset :
85 Warheog tại Warhog Dot Net ¶
12 năm trước
Before unset : hello geeks
After unset :
86Before unset : hello geeks
After unset :
87Before unset : hello geeks
After unset :
88Before unset : hello geeks
After unset :
89Before unset : hello geeks
After unset :
90Before unset : hello geeks
After unset :
91Before unset : hello geeks
After unset :
92Before unset : hello geeks
After unset :
93Before unset : hello geeks
After unset :
94Before unset : hello geeks
After unset :
95Before unset : hello geeks
After unset :
96Before unset : hello geeks
After unset :
97Before unset : hello geeks
After unset :
98
7 Edouard Dot Berge tại Gmail Dot Com ¶ ¶
13 năm trước
$variable = null;
00$variable = null;
01$a
1
$variable = null;
03 Dan at--nospam-- cubeland dot co dot uk ¶ ¶
15 năm trước
$variable = null;
04 Lion_Cat tại Mail Ru ¶ ¶
13 năm trước
$variable = null;
05$variable = null;
06Before unset : hello geeks
After unset :
17$variable = null;
08 Dan at--nospam-- cubeland dot co dot uk ¶ ¶
17 năm trước
$variable = null;
09$variable = null;
10$variable = null;
11
Thorry tại Thorry Dot Net ¶
18 năm trước
$variable = null;
12$variable = null;
13$variable = null;
14$variable = null;
15Before unset : hello geeks
After unset :
17$variable = null;
17 Pauljamescampbell tại Gmail Dot Com ¶
¶
14 năm trước
$variable = null;
18$variable = null;
19$variable = null;
20
7unset () phá hủy các biến được chỉ định.Hành vi của unset () bên trong một hàm có thể thay đổi tùy thuộc vào loại biến bạn đang cố gắng phá hủy.Nếu một biến toàn cầu hóa không được đặt () bên trong một hàm, chỉ có biến cục bộ bị phá hủy.destroys the specified variables. The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. If a globalized variable is unset() inside of a function, only the local variable is destroyed.
Các chức năng quản lý bộ nhớ PHP được trình điều khiển gốc MySQL gọi thông qua trình bao bọc nhẹ.Trong số những người khác, trình bao bọc làm cho việc gỡ lỗi dễ dàng hơn.Máy chủ MySQL khác nhau và các API máy khách khác nhau phân biệt giữa các bộ kết quả được đệm và không có nội dung.invoked by the MySQL Native Driver through a lightweight wrapper. Among others, the wrapper makes debugging easier. The various MySQL Server and the various client APIs differentiate between buffered and unbuffered result sets.
Hàm unset () là một hàm sẵn có trong PHP được sử dụng để hủy bỏ một biến được chỉ định.unset() function is an inbuilt function in PHP which is used to unset a specified variable.