【发布时间】:2017-11-10 16:32:42
【问题描述】:
这是我用来为 WordPress 网站创建数组的代码。
foreach ($terms as $item) {
$location_no++;
$term_id = $item->term_id;
$term_name = $item->name;
$latitude = get_field('latitud', 'term_' . $term_id);
$longitude = get_field('longitud', 'term_' . $term_id);
// Populate the array!
$locations[$location_no] = array (
'id' => $location_no,
'lat' => $latitude,
'long' => $longitude,
'name' => $term_name,
);
}
echo '<pre>';
print_r($locations);
echo '</pre>';
print_r() 产生这个:
Array
(
[1] => Array
(
[id] => 1
[lat] => 40.423560
[long] => -3.702541
[name] => Madrid
)
[2] => Array
(
[id] => 2
[lat] => 40.423560
[long] => -3.702541
[name] => Madrid
)
)
...
但是,当我切换到 php7.1 时,该数组不再起作用,而我得到了这个:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
$terms 的 var_dump() 会产生这样的结果:
array(1) {
[0]=>
object(WP_Term)#7136 (10) {
["term_id"]=>
int(28)
["name"]=>
string(6) "Madrid"
["slug"]=>
string(6) "madrid"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(28)
["taxonomy"]=>
string(14) "trip_locations"
["description"]=>
string(0) ""
["parent"]=>
int(71)
["count"]=>
int(5)
["filter"]=>
string(3) "raw"
}
}
为什么会这样?
【问题讨论】:
-
如果你使用 var_dump($terms); 你会得到什么?
-
@RemcoK。我已经用输出修改了我的问题。