0

I have a JSON data about 150 users, i have convert that into java script array, now what i want it to pass this array to PHP, So that i can perform further operations on this array.

var JSONString = '[{'user_id' : "1", "user_name" : "abc", "email":"abc@gmail.com"}, {"user_id":"2", "user_name":"abc", "email":"abc2@gmail.com"}]'

var JSONObject = JSON.parse(JSONString);

 for (var key in JSONObject) {
    if (JSONObject.hasOwnProperty(key)) {
      console.log(JSONObject[key]["user_id"] + ", " + JSONObject[key]["user_name"]);
    }
  }

now what i need it to pass this array to PHP array variable , that will loop through and perform further operation. i have seen some solution that display it on html with JavaScript, but i don't need that. i need this array object in php array variable.

Muhammad Taqi
  • 5,356
  • 7
  • 36
  • 61

1 Answers1

0

Instead of parsing JSON string in JavaScript, pass it directly to PHP and use PHP function

json_decode($json, true)

it will give you data in array format.

PravinS
  • 2,640
  • 3
  • 21
  • 25