我有这种格式的数组:
Array
(
[0] => some text
[1] => some text
[2] => some text
[3] => some text
[4] =>
[5] =>
[6] => some text
[7] => some text
[8] => some text
[9] =>
[10] =>
[11] =>
[12] =>
[13] => some text
[14] => some text
)
此数组的长度可能会发生变化,有时ID如上所示为空白。
我需要将此数组保存到具有70列(所有VARCHAR)的MySQL表中,但不会以上述格式保存。我知道数组必须是这样的:
Array
(
[ModelName] => Array
(
[fieldname1] => 'value'
[fieldname2] => 'value'
)
)
如何将上述数组修改为以下结构?所有列名都是str后跟列所在的数字(即str1,str2等)
答案 0 :(得分:0)
将数组转换为蛋糕理解的内容,然后保存它
$modelArray = array('ModelName' => array());
foreach( $yourArray as $index => $value ){
$modelArray['ModelName']['str' . $index] = $value
}
$this->ModelName->save($modelArray);