我有3个JSON字符串与POST进来,并希望将它们合并到一个2维数组中,并以JSON格式保存到数据库中。 对于这个例子,我有图片的URL,ALT描述和布尔isfavoritePHP将数组合并到2D JSON中
$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);
你想要的三个阵列是在阵列之前清理数字索引......吧?并且你想将JSON保存在数据库中,对吗? – Gordon 2010-11-02 14:08:27
是的,没错。 – FFish 2010-11-02 14:09:56