我正在尝试将 javascript 函数转换为 php,但我的数组存在一些问题。我需要遍历数组元素,将它们全部乘以一定数量,但它不会改变值。很确定这是因为我的语法 $coordinates_p[i][0] *= $scale; 不正确,但我不确定它应该是什么!
测试代码:
<?php
print "Starting.<br/>";
$scale = 100;
$coordinates_p = array();
$i = 0;
$x_coordinate = 1;
$y_coordinate = 2;
while ($i <= 1) {
$coordinates_p[$i] = array(0 => $x_coordinate, 1 => $y_coordinate);
$x_coordinate += 1;
$y_coordinate += 2;
$i++;
}
print "Unscaled: ";
print_r ($coordinates_p);
print "<br/>";
$i = 0;
while (isset($coordinates_p[i])) {
$coordinates_p[i][0] *= $scale;
$coordinates_p[i][1] *= $scale;
$i++;
}
print "Scaled: ";
print_r ($coordinates_p);
print "<br/>";
print "Finished.";
?>