输出格式:
Array (
[0] => (19.979802102871425,73.78671169281006)
[1] => (19.97978382724978,73.78682289971039)
[2] => (19.979765551626006,73.78697712672874)
)
期望输出:
Array (
[0] =>
[lag]=>19.979802102871425,
[long]=>73.78671169281006,
[1] => [lag]=>19.97978382724978,
[long]=>73.78682289971039
[2] => [lag]=>19.979765551626006,
[long]=>73.78697712672874
)
下面的代码工作没有给我想要的输出,因为我不知道在数组
中添加两个关联元素 foreach($_POST['textbox'] as $value):
$value = str_replace(array('(',')'), '',$value);
foreach (explode(',', $value) as $topic) :
list($name, $items) =$topic;
///stuck up here
}
$test[] = explode(',', $value);
endforeach;
endforeach;
可以建议代码的变化,因为我参考了以下链接,但预期的结果与我的不同。提前感谢php-explode-and-put-into-arrayexplode-function
你可以试试-
foreach($your_array As &$array) {
$temp = explode(',', str_replace(array('(', ')'), '', $array)); // replace the ()s & explode the value
$array = array('lat' => $temp[0], 'long' => $temp[1]); // store with keys
}
试试这个:
foreach($array as $value){
list($lat,$lng) = explode(',',trim(trim($value,')'),'('));
$out[] = array( 'lat' => $lat , 'lng' => $lng);
}
var_dump($out);