Variable references about PHP constants and variables

慕斯
Release: 2023-03-09 21:24:02
Original
2224 people have browsed it

The previous article introduced you to "How to use PHP to build environment variables? What other environment variables do you know? 》, this article continues to introduce to you the variable references of PHP constants and variables:

About the variable references of PHP constants and variables

Variable references about PHP constants and variables

Write two pieces of code respectively, as shown below:

<?php
$fo =8;
//$fo的值为8,将8赋值    
$bar = $fo;
//$bar的值刚开始是8,现在将值改为6
$bar = 6;
//$bar的结果为6
echo $bar.&#39;<br />&#39;;
//$fo的结果为8
echo $fo.&#39;<br />&#39; 
?>
Copy after login

The running result is as follows:

Variable references about PHP constants and variables

Second The code snippet is as follows:

<?php
$fo =8;
//$fo的值为8,将8赋值    
$bar = &$fo;         //在$fo前加一个取地址符&
//$bar的值刚开始是8,现在将值改为6
$bar = 6;
//$bar的结果为6
echo $bar.&#39;<br />&#39;;
//$fo的结果为8
echo $fo.&#39;<br />&#39; 
?>
Copy after login

The running result is as follows:

Variable references about PHP constants and variables

According to the above code, it can be concluded that Why do both results become 6?

Reason: In $bar = &$fo, the two of them share the same address, which means that no matter which parameter you change, their values ​​will be changed accordingly. Change, that is, no matter how the value of $fo or $bar changes, $fo changes to $bar, and $bar changes, $fo will also change.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Variable references about PHP constants and variables. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template