PHP代码:强大的文本
// $files would be stored into mysql db and will retrieve as original
$files = array('1' => '1,2,4,5', '5' => '4,5,7,23,56','8' => '45,23,56,67');
而且数据库表file's allFile[char]
'1' => '1,2,4,5', '5' => '4,5,7,23,56','8' => '45,23,56,67'
我想我必须在阵列数据转换成字符串,然后存储到数据库,但implode
只有array value
没有key
.S o,我是否应该使用foreach loop
将key/value
变成字符串?
foreach ($files as $key => $value){
$str .= $key.'=>'.$value.','; // remove the last comma of the $str
}
,当我取回$str
形式的数据库,我得到:
$files = array($str);
所以,我是做正确的方法是什么?!
非常感谢!
如果您将数组的结构转换为表格并将这些元素作为行插入,会不会感觉更容易访问?如果您只是要求他将文本块挂在一行上,数据库可能会感觉过分。 – erisco 2011-02-23 06:00:43