Home > Backend Development > PHP Tutorial > 谁能说说这串PHP代码的运行原理?

谁能说说这串PHP代码的运行原理?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:25:08
Original
1182 people have browsed it

$array=array(1,2,3,4,5);
foreach($array as &$v){

}

$v=0;
var_dump($array);
/**结果
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
&int(0)
}
*/

回复内容:

$array=array(1,2,3,4,5);
foreach($array as &$v){

}

$v=0;
var_dump($array);
/**结果
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
&int(0)
}
*/

不就是引用嘛。
array的最后一个值与$v指向同一个地址。

如果你 $array[4] = 999; 那么 $v也是999.

参考这个 => http://segmentfault.com/q/1010000002676308

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template