0

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 is not given me desired output as i am unaware of adding two associate element in array

   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;

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

2 Answers 2

1

You can try this -

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

simple sleek and awesome thanks @b0s3 accepting the answer
0

Try this :

 foreach($array as $value){
         list($lat,$lng) = explode(',',trim(trim($value,')'),'('));
         $out[] = array( 'lat' => $lat , 'lng' => $lng);
 }
 var_dump($out);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.