Comment transfomer une chaine de caractère en array
Bonjour,
Je stocke dans une base mySQL ceci (dans ma colonne 'coordinates'
Citation:
[[[51.696395158699,-1.131591796875],[51.406059404993,-1.4117431640625],[51.282534682475,-0.87890625],[51.658926648801,-0.5328369140625],[51.696395158699,-1.131591796875]]]
et je dois mettre cette valeur ici
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
foreach($result as $i => $collection)
{
$feature = array(
'type' => 'Feature',
'geometry' => array(
'type' => 'Polygon',
//'coordinates' => $collection['coordinates']
'coordinates' => array($collection['coordinates'])
//'coordinates' => [[[-1.6040039062500002,52.09975692575725],[-2.0544433593750004,51.92733099026087],[-1.7358398437500002,51.70320428462806],[-0.9448242187500001,51.951036645095904],[-1.6040039062500002,52.09975692575725]]]
),
'properties'=> array(
'id' => $collection['id'],
'name' => $collection['name']
)
);
array_push($geojson['features'], $feature);
//array_push($geojson, $collection['coordinates']);
}; |
Le probleme c'est ceci ne marche pas
Code:
1 2 3
|
//'coordinates' => $collection['coordinates']
'coordinates' => array($collection['coordinates']) |
mais si je l'écris "en dur", ca marche
Code:
1 2
|
'coordinates' => [[[-1.6040039062500002,52.09975692575725],[-2.0544433593750004,51.92733099026087],[-1.7358398437500002,51.70320428462806],[-0.9448242187500001,51.951036645095904],[-1.6040039062500002,52.09975692575725]]] |
etant donnée que ce que j'extrait est du texte, comment je peux convertir ce texte en array??
En fait c'est ceci
Code:
'coordinates' => $collection['coordinates']
et ceci
Code:
1 2
|
'coordinates' => [[[-1.6040039062500002,52.09975692575725],[-2.0544433593750004,51.92733099026087],[-1.7358398437500002,51.70320428462806],[-0.9448242187500001,51.951036645095904],[-1.6040039062500002,52.09975692575725]]] |
c'est la meme chose, sauf que l'un est un texte
Merci pour vos lumières