array_splice函数结果赋值解决思路

WBOY
Release: 2016-06-13 12:21:18
Original
1226 people have browsed it

array_splice函数结果赋值
$arr1 = array(1,2,3);
$arr2 = array(3,4,5);
$arr1 = array_splice($arr2,1,1);
print_r($arr1);


结果是Array ( [0] => 4 )
按理说,赋值运算符在最后完成array_splice函数后才进行,
那么 array_splice($arr2,1,1)得到的数组$arr2内的值应该是(3,4),
然后运算“=”,则得到$arr1数组的内容应该是(3,4),但是实际上运行整个
$arr1 = array_splice($arr2,1,1),却得到$arr1数组的内容为(4),求解。
------解决思路----------------------
手册中数的很明白了:返回一个包含被移除单元的数组
仅从返回结果上看, array_splice($arr2,1,1) 等同于 array_slice($arr2,1,1)
但前者已经改变了 $arr2 的原始状态

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!