PHP最长执行时间?
我可能在这段代码中遗漏了一些东西,看起来像是某种循环问题,下面是代码,我不知道发生了什么:PHP最长执行时间?,php,execution,Php,Execution,我可能在这段代码中遗漏了一些东西,看起来像是某种循环问题,下面是代码,我不知道发生了什么: function clearBoard() { //initialize board with a . in each cell global $board, $boardData; for ($row = 0; $row < $boardData["height"]; $row++) { for ($col = 0;
function clearBoard() {
//initialize board with a . in each cell
global $board, $boardData;
for ($row = 0; $row < $boardData["height"]; $row++) {
for ($col = 0; $col < $boardData["width"]; $col++) {
$board[$row][$col] = ".";
} //end col for loop
} //end row for loop
} //end clearBoard
函数clearBoard(){
//在每个单元中用.初始化电路板
全球$board,$boardData;
对于($row=0;$row<$boardData[“height”];$row++){
对于($col=0;$col<$boardData[“宽度”];$col++){
$board[$row][$col]=“;
}//循环结束列
}//循环结束行
}//端部透明板
多谢各位
Alex该代码没有天生的问题;它以非常合理的方式做了显而易见的事情。如果花的时间太长,那么网格就太大了。就这么简单 话虽如此,有一种方法可以加快速度:使用:
据我所知,
array\u fill
是用C实现的,应该比PHP快。请打印$boardData[“height”]
和$boardData[“width”]
,是否缺少数组声明?
function clearBoard() {
global $board, $boardData;
$board = array_fill(0, $boardData["height"],
array_fill(0, $boardData["width"], "."));
}