怎么用循环方式改变数组里的值?

WBOY
Release: 2016-06-20 12:33:27
Original
1768 people have browsed it

$a=array(1,2,3,4,5);
var_dump($a);
foreach($a as $b){
$b=$b-1;
}

var_dump($a);

这样前后两次打印出来的 $a 是一样的都是 (1,2,3,4,5),怎么让第二次 $a=(0,1,2,3,4)


回复讨论(解决方案)

$a=array(1,2,3,4,5);
var_dump($a);
foreach($a as  &$b){
$b=$b-1;
}

var_dump($a);

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