php - How to convert multidimensional array into json object -


i have issue in array json conversion, have array , want convert array json objects, desired output given below 1 please me.

php array

    array (     [0] => array         (             [application_id] => 132             [application_status] => submitted             [reference_number] =>              [salutation] =>              [first_name] =>              [middle_name] =>              [last_name] =>              [mother_name] =>            )      [1] => array         (             [application_id] => 148             [application_status] => submitted             [reference_number] =>              [salutation] =>              [first_name] =>              [middle_name] =>              [last_name] =>              [mother_name] =>            )      [2] => array         (             [application_id] => 154             [application_status] => submitted             [reference_number] =>              [salutation] =>              [first_name] =>              [middle_name] =>              [last_name] =>              [mother_name] =>            )      [3] => array         (             [application_id] => 182             [application_status] => submitted             [reference_number] =>              [salutation] =>              [first_name] =>              [middle_name] =>              [last_name] =>              [mother_name] =>            )      [4] => array         (             [application_id] => 186             [application_status] => submitted             [reference_number] =>              [salutation] =>              [first_name] =>              [middle_name] =>              [last_name] =>              [mother_name] =>             )  ) 

convert above array json object this:

[         {             "application_id": "1",             "application_status": "0",             "reference_number": "/index",             "salutation": "index",             "first_name": "index",             "middle_name": "home",             "last_name": "1",          },         {             "application_id": "1",             "application_status": "0",             "reference_number": "/index",             "salutation": "index",             "first_name": "index",             "middle_name": "home",             "last_name": "1",          },         {             "application_id": "1",             "application_status": "0",             "reference_number": "/index",             "salutation": "index",             "first_name": "index",             "middle_name": "home",             "last_name": "1",          },         {             "application_id": "1",             "application_status": "0",             "reference_number": "/index",             "salutation": "index",             "first_name": "index",             "middle_name": "home",             "last_name": "1",          },         {             "application_id": "1",             "application_status": "0",             "reference_number": "/index",             "salutation": "index",             "first_name": "index",             "middle_name": "home",             "last_name": "1",          },  ]   

your desired output suggests array of objects. loop on them , encode each subarray json string, , decode again obtain object:

foreach($array $k =>$a){     $array[$k] = json_decode(json_encode($a)); } 

if mean want array of json strings, omit json_decode:

foreach($array $k =>$a){     $array[$k] = json_encode($a); } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -