尽管我认为wordpress与我的问题没有任何关系,但我有工作要在wordpress网站上进行一些迁移。 因此,我从序列化的表(id,值)中获取了一组数据。
根据功能,我想将序列化的数据放入数组中。该算法可以对前86条记录做得很好。
如果仅对86条记录运行该算法,我将立即获得所有正确的数据。但是,当我运行它87次或更多次时,它就开始加载。显然,仍然可以达到最大执行时间限制有多长时间。
我检查了第87条记录是否有奇怪之处,但我什么也看不到。有什么想法可以解决这个问题吗?
代码如下:
global $wpdb;
$houses_built_years = $wpdb->get_results('SELECT post_id, meta_value FROM bp100_postmeta WHERE meta_key = "epites_eve"');
foreach ($houses_built_years as $house_built_years) {
if ($house_built_years->meta_value) {
$years = unserialize($house_built_years->meta_value);
} else {
continue;
}
$build = array(array());
$series = 0; $year = 0;
while (count($years)) {
if ($build[$series][$year] && (min($years) - $build[$series][$year] == 1)) {
$year++;
$build[$series][$year] = min($years);
unset($years[array_search(min($years), $years)]);
} else if ($build[$series][$year]) {
$year = 0;
$series++;
$build[$series][$year] = min($years);
unset($years[array_search(min($years), $years)]);
} else {
$build[$series][$year] = min($years);
unset($years[array_search(min($years), $years)]);
}
}
$repeater = array();
foreach ($build as $series) {
if (count($series) > 1) {
$repeater[] = $series[0] . ' - ' . $series[count($series) - 1];
} else {
$repeater[] = $series[0];
}
}
}
以下是一些记录示例(算法在id = 30517处中断):
30279 1201 epites_eve a:1:{i:0; s:4:“ 1898”;}
30338 1202 epites_eve a:1:{i:0; s:4:“ 1891”;}
30397 1203 epites_eve a:1:{i:0; s:4:“ 1894”;}
30517 1205 epites_eve a:1:{i:0; s:4:“ 1897”;}
30577 1206 epites_eve a:1:{i:0; s:4:“ 1891”;}