0

I am developing an android application to store and invite user contacts on the server.

the array I am having from android is JSON format.

$a='[
      {"phone":"(785) 583-7086","name":"Website 22-2-16"},
      {"phone":"(904) 136-2961","name":"Abhi"}
]';

I want these two attributes phone and name sent into an iteration in PHP and store in respective columns like name and phone in MySQL using PHP

1
  • 1
    decode to convert in array and loop through it and store. you should have searched a bit. Commented Mar 4, 2017 at 12:08

1 Answer 1

1

Decode the json string using json_decode() function and loop through the decoded array using foreach loop, like this:

$a='[{"phone":"(785) 583-7086","name":"Website 22-2-16"}, {"phone":"(904) 136-2961","name":"Abhi"}]';

$decoded_json = json_decode($a, true);
foreach($decoded_json as $details){
    // phone: $details['phone']
    // name: $details['name']
    // perform your INSERT operation
}
Sign up to request clarification or add additional context in comments.

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.