Home > Backend Development > PHP Tutorial > 求知道的大大解释一下这里的引用

求知道的大大解释一下这里的引用

WBOY
Release: 2016-06-06 20:41:53
Original
1013 people have browsed it

<code>请输入代码
 <?php $arr1=array(1,2);
 $str=&$arr1[0];      //这里的引用对后面到底有什么影响
 $arr2=$arr1;
 $arr1[0]='a';
 print_r($arr2);    //这里打出来的为什么不是array(1,2),而是array('a',2)
 ?>
</code>
Copy after login
Copy after login

回复内容:

<code>请输入代码
 <?php $arr1=array(1,2);
 $str=&$arr1[0];      //这里的引用对后面到底有什么影响
 $arr2=$arr1;
 $arr1[0]='a';
 print_r($arr2);    //这里打出来的为什么不是array(1,2),而是array('a',2)
 ?>
</code>
Copy after login
Copy after login

看不懂$str=&$arro[0];,测试了打出来的是[1, 2],而且不报错。

版本: php 5.4

Related labels:
php
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