Ceci est le code que j'utilise pour créer un tableau pour un site WordPress.Pourquoi cette création de tableau ne fonctionne-t-elle pas dans php7?
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>';
le print_r() produit ceci:
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
)
)
...
Cependant quand je passer à php7.1, le tableau ne fonctionne plus et je reçois ceci:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
A var_dump() de $ terms produit ceci:
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"
}
}
Pourquoi oh pourquoi cela arrive-t-il?
Qu'est-ce que vous obtenez si vous var_dump (termes $); ? –
@RemcoK. J'ai modifié ma question avec la sortie. –