explode associative array in php and adding two fields in the array -


output of form:

array (     [0] => (19.979802102871425,73.78671169281006)     [1] => (19.97978382724978,73.78682289971039)     [2] => (19.979765551626006,73.78697712672874)  ) 

expect output:

array (     [0] =>            [lag]=>19.979802102871425,           [long]=>73.78671169281006,        [1] => [lag]=>19.97978382724978,            [long]=>73.78682289971039     [2] => [lag]=>19.979765551626006,              [long]=>73.78697712672874  ) 

following code working not given me desired output unaware of adding 2 associate element in array

   foreach($_post['textbox'] $value):         $value = str_replace(array('(',')'), '',$value);        foreach (explode(',', $value) $topic) :             list($name, $items) =$topic;            ///stuck here            }              $test[] = explode(',', $value);        endforeach;                                  endforeach; 

could please suggest changes in code reffered following links expected out different mine.thanks in advance php-explode-and-put-into-array explode-function

you can try -

foreach($your_array &$array) {    $temp = explode(',', str_replace(array('(', ')'), '', $array)); // replace ()s & explode value    $array = array('lat' => $temp[0], 'long' => $temp[1]); // store keys } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -