Hướng dẫn how can you get the reference of a variable in php? - làm thế nào bạn có thể lấy tham chiếu của một biến trong php?

Bạn có thể chuyển một biến bằng cách tham chiếu đến một hàm để hàm có thể sửa đổi biến. Cú pháp như sau:

Lưu ý: Không có dấu hiệu tham chiếu trên lệnh gọi hàm - chỉ trên các định nghĩa chức năng. Định nghĩa chức năng một mình là đủ để vượt qua chính xác đối số bằng cách tham khảo.: There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference.

Những điều sau đây có thể được thông qua bằng cách tham khảo:

  • Biến, tức là foo[$a]
  • Các tài liệu tham khảo được trả về từ các chức năng, tức là:

    Xem thêm về trả lại bằng cách tham khảo.

Không có biểu thức nào khác nên được truyền qua tham chiếu, vì kết quả không được xác định. Ví dụ: các ví dụ sau về việc truyền qua tham chiếu không hợp lệ:

Tnestved tại Yahoo Dot Com ¶

8 năm trước

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately.

ccb_bc tại hotmail dot com ¶

3 năm trước

Mike tại Eastghost Dot Com ¶

7 năm trước

beware unset[]  destroys references

$x = 'x';
change[ $x ];
echo $x; // outputs "x" not "q23"  ---- remove the unset[] and output is "q23" not "x"

foo[$a]0

foo[$a]1

Nickshanks tại Nickshanks Dot Com ¶

5 năm trước

foo[$a]2

foo[$a]3

foo[$a]4

foo[$a]5

Rob tại Librobert Dot Net

10 tháng trước

foo[$a]6

foo[$a]7

foo[$a]8

foo[$a]9

0

1

foo[$a]1

Jason Steelman ¶

2 năm trước

3

4

foo[$a]1

PHPNet tại Holodyn dot com ¶

8 năm trước

6

7

foo[$a]1

ccb_bc tại hotmail dot com ¶

3 năm trước

9

0

1

2

3

4

Mike tại Eastghost Dot Com ¶

2 năm trước

5

6

7

8

foo[$a]1

PHPNet tại Holodyn dot com ¶

diabolos @t gmail dot com

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 0

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 1

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 2

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 3

10 năm trước

Yiangforwork tại Gmail Dot Com ¶

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 4

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 5

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 6

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 7

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 8

By removing the ability to include the reference sign on function calls where pass-by-reference is incurred [I.e., function definition uses &], the readability of the code suffers, as one has to look at the function definition to know if the variable being passed is by-ref or not [I.e., potential to be modified].  If both function calls and function definitions require the reference sign [I.e., &], readability is improved, and it also lessens the potential of an inadvertent error in the code itself.  Going full on fatal error in 5.4.0 now forces everyone to have less readable code.  That is, does a function merely use the variable, or potentially modify it...now we have to find the function definition and physically look at it to know, whereas before we would know the intent immediately. 9

Tianyiw tại VIP Dot qq dot com ¶

5 năm trước

0

$x = 10;
[function[] use [
$x]{
   
$x = $x*$x;
   
var_dump[$x]; // 100
}][];
var_dump[$x]; // 10

// Now the magic happens with using the reference [&]. Now we are actually accessing the contents of the '$y' variable that is outside the scope of the function. All the actions that we perform with the variable '$y' within the function will be reflected outside the scope of this same function. Remembering this would be an impure function in the functional paradigm, since we are changing the value of a variable by reference.

$y = 10;
[function[] use [&
$y]{
   
$y = $y*$y;
   
var_dump[$y]; // 100
}][];
var_dump[$y]; // 100
?>
1

Jason Steelman ¶

5 năm trước

$x = 10;
[function[] use [
$x]{
   
$x = $x*$x;
   
var_dump[$x]; // 100
}][];
var_dump[$x]; // 10

// Now the magic happens with using the reference [&]. Now we are actually accessing the contents of the '$y' variable that is outside the scope of the function. All the actions that we perform with the variable '$y' within the function will be reflected outside the scope of this same function. Remembering this would be an impure function in the functional paradigm, since we are changing the value of a variable by reference.

$y = 10;
[function[] use [&
$y]{
   
$y = $y*$y;
   
var_dump[$y]; // 100
}][];
var_dump[$y]; // 100
?>
2

$x = 10;
[function[] use [
$x]{
   
$x = $x*$x;
   
var_dump[$x]; // 100
}][];
var_dump[$x]; // 10

// Now the magic happens with using the reference [&]. Now we are actually accessing the contents of the '$y' variable that is outside the scope of the function. All the actions that we perform with the variable '$y' within the function will be reflected outside the scope of this same function. Remembering this would be an impure function in the functional paradigm, since we are changing the value of a variable by reference.

$y = 10;
[function[] use [&
$y]{
   
$y = $y*$y;
   
var_dump[$y]; // 100
}][];
var_dump[$y]; // 100
?>
3

$x = 10;
[function[] use [
$x]{
   
$x = $x*$x;
   
var_dump[$x]; // 100
}][];
var_dump[$x]; // 10

// Now the magic happens with using the reference [&]. Now we are actually accessing the contents of the '$y' variable that is outside the scope of the function. All the actions that we perform with the variable '$y' within the function will be reflected outside the scope of this same function. Remembering this would be an impure function in the functional paradigm, since we are changing the value of a variable by reference.

$y = 10;
[function[] use [&
$y]{
   
$y = $y*$y;
   
var_dump[$y]; // 100
}][];
var_dump[$y]; // 100
?>
4

foo[$a]1

Làm thế nào để bạn tham khảo một biến trong PHP?

Trong PHP, tên biến và nội dung biến là khác nhau, vì vậy cùng một nội dung có thể có tên khác nhau. Một biến tham chiếu được tạo bằng tiền tố & ký vào biến gốc. Do đó b = & a sẽ có nghĩa là bisareferewncevarableofa.prefixing & sign to original variable. Hence b=&a will mean that bisareferewncevariableofa.

Tài liệu tham khảo của một biến là gì?

Biến tham chiếu là một tên thay thế của biến đã có. Nó không thể được thay đổi để giới thiệu một biến khác và nên được khởi tạo tại thời điểm khai báo và không thể là null. Toán tử '&' được sử dụng để khai báo biến tham chiếu.an alternate name of already existing variable. It cannot be changed to refer another variable and should be initialized at the time of declaration and cannot be NULL. The operator '&' is used to declare reference variable.

Toán tử tham chiếu Php là gì?

Sử dụng = & toán tử để tạo biến không tồn tại trong PHP.Sử dụng toán tử = & toán để trỏ nhiều hơn một biến vào cùng một giá trị [vị trí bộ nhớ] trong PHP.Sử dụng = & toán tử để liên kết nhiều hơn một biến trong PHP.Sử dụng = & toán tử để hủy liên kết nhiều hơn một biến trong PHP.. Use the =& Operator to Point More Than One Variable to the Same Value [Memory Location] in PHP. Use the =& Operator to Link More Than One Variable in PHP. Use the =& Operator to Unlink More Than One Variable in PHP.

$ _ Nhận biến là gì?

PHP $ _GET là một biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu biểu mẫu sau khi gửi biểu mẫu HTML với Phương thức = "GET".$ _GET cũng có thể thu thập dữ liệu được gửi trong URL.a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL.

Bài Viết Liên Quan

Chủ Đề