我不确定为什么在php中出现以下内容
<?php
//make the array first
$example = array();
$i = 0;
while($i < 10) {
$example[$i++] = $i;
}
var_dump($example);
//looks good here. As expected
$i = 0;
while ($i < 10) {
$example[$i] = $i . " " . $example[$i++];
}
var_dump($example);
//this one should contain each of the values again for example
$expected = array(
"0 0",
"1 1",
"2 2",
//etc
);
在Java中做同样的事情
public class append
{
public static void main(String[] args) {
String[] array = new String[10];
int i = 0;
while (i < 10) {
array[i] = i++ + "";
}
i = 0;
while (i < 10) {
array[i] = i + " " + array[i++];
}
i = 0;
while(i < 10) {
System.out.println (array[i++]);
}
}
}
它返回正确,我唯一能想到的是运算符优先级。是因为[
在PHP和++
中排名++
超出了所有内容吗?
很抱歉有很多代码,认为它会比我更好地解释