Currently, my front end website uses a .js file that is hosted on dropbox as a "database". It is essentially a Javascript dictionary that is called, and then used. This is the format.
myDictionary = {
"Tag1":["Tag1","info1","info2"],
"Tag2":["Tag2","info1","info2"],
...
...
}
myDictionary2 = {
"Tag1":["Tag1","info1","info2"],
"Tag2":["Tag2","info1","info2"],
...
...
}
I'm starting to transition into PHP, and I wanted to know if it was possible to add new entries to this dictionary without messing things up. Basically, what I am asking is if there is a way of adding entires to a javascript dictionary, preferably without just adding the text, as it may get complicated. Thank You!
Yes, it's possible using json_decode() and 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"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With