How To Write To Javascript Object With PHP -


currently, front end website uses .js file hosted on dropbox "database". javascript dictionary called, , used. format.

mydictionary = { "tag1":["tag1","info1","info2"], "tag2":["tag2","info1","info2"], ... ...  } mydictionary2 = { "tag1":["tag1","info1","info2"], "tag2":["tag2","info1","info2"], ... ...  } 

i'm starting transition php, , wanted know if possible add new entries dictionary without messing things up. basically, asking if there way of adding entires javascript dictionary, preferably without adding text, may complicated. thank you!

yes, it's possible using json_decode() , json_encode():

<?php  $mydictionary = json_decode('{     "tag1":["tag1","info1","info2"],     "tag2":["tag2","info1","info2"] }');  $mydictionary->tag3 = ["tag3","info1","info2"];  echo json_encode($mydictionary, json_pretty_print); 

output:

{     "tag1": [         "tag1",         "info1",         "info2"     ],     "tag2": [         "tag2",         "info1",         "info2"     ],     "tag3": [         "tag3",         "info1",         "info2"     ] } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -