【发布时间】:2015-08-27 20:02:38
【问题描述】:
我编写了一个在 drupal 中运行的简单 php 脚本。它从不同的服务器导入 json 并将其转换为多维数组。当我添加一个稍微重写数组的 for 循环时,加载时间从 1 秒增加到 5 秒。我在这里做错了吗?
部分原始“快速”代码:
public function give_nausys_request_rew_array() {
$this->jsonarray = drupal_json_decode($this->give_nausys_request());
$this->jsonarray = $this->jsonarray[reservations];
return $this->jsonarray;
}
“慢”代码的一部分:
public function give_nausys_request_rew_array() {
$this->jsonarray = drupal_json_decode($this->give_nausys_request());
$this->jsonarray = $this->jsonarray[reservations];
$this->arraycount = count($this->jsonarray)-1;
for ($i = 0; $i <= $this->arraycount; $i++) {
$this->jsonarray[$i][GUID] = $this->jsonarray[$i][yachtId].'-'.$this->jsonarray[$i][periodFrom].'-'.$this->jsonarray[$i][periodTo];
}
return $this->jsonarray;
}
【问题讨论】:
标签: php arrays drupal drupal-7