I have 3 JSON strings coming in with POST and want to merge these into a 2 dimensional array and save in JSON format to the database.
For this example I have image URL’s, alt descriptions and booleans isfavorite
$url_arr = json_decode('["http://site.com/001.jpg","http://site.com/003.jpg","http://site.com/002.jpg"]');
$alt_arr = json_decode('["testing internat chars àèéìòóù stop","second description",""]'); // UTF-8 supported
$isFav_arr = json_decode('["true", "false", "false"]'); // strings need to be converted to booleans
// merge into 2 dimensional array
// $img_arr = array_merge($url_arr, $alt_arr, $isFav_arr); // doesn't work, just add's to the end
// ...
// save 2D JSON in database
$to_db = json_encode($img_arr);
Just string concatenate:
Unless you want to work with the values in the Json string, you dont need any en/decoding.
You can use http://www.jsonlint.com/ to validate it (removed jsonlint and
print_rdumps to make some space)