我有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