json_encode & JSON.parse

697 0 0 0

Last Updated : 2024-04-18 22:37:21

Sometimes, you will need to transform a php array into a json string in order to send it to a javascript code to work on it. In this case you will have to use the php built in function json_encode($phpArray) and then in javascript code, you have to transform this json string into an object so that you can iterate over it or do whatever you want with it, Now on javascript you can do this by using JSON.parse(allSearchableTags)


  1. In your php code
    json_encode(['one', 'two', 'three']);


Mohammed Anwar

Mohammed Anwar

Experienced technical lead PHP, MySQL and Laravel Developer for 15+ years, with proven ability to develop and create high-quality and optimized web applications. Great ability to build and optimize database design, schema and queries. Versed programing trainer and instructor delivering web courses and helping others to get into the field in a timely manner. Fast and eager learner for new technologies .