两次结果输出不一样,老师解释下,为啥第一次打印的是字符串
$stack ='';
$collections = [1,2,3,4,5,6,7];
foreach($collections as $key => $collection) {
$stack[$key] = $collection . '_' . $key;
}
var_dump($stack);//打印出来是一个字符串,理解?string(7) "1234567"
echo '<br>';
$stack =[];
$collections = [1,2,3,4,5,6,7];
foreach($collections as $key => $collection) {
$stack[$key] = $collection . '_' . $key;
}
var_dump($stack);//输出是数组
/*
array(7) {
[0]=>
string(3) "1_0"
[1]=>
string(3) "2_1"
[2]=>
string(3) "3_2"
[3]=>
string(3) "4_3"
[4]=>
string(3) "5_4"
[5]=>
string(3) "6_5"
[6]=>
string(3) "7_6"
*/
9
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星