-1
我嘗試在if條件中附加我的數據數組。我正在使用array_push
函數來完成它第一次使用這個函數來追加數組。我正在使用條件,以便如果用戶在表單中添加了值,它會更新字段,否則它不會影響字段。問題是其更新不及時的數據庫,其無法設置字段,因爲它顯示了在「字段列表」在php/CodeIgniter中追加數組
$fid = 2;
$password = "test_pass";
$title = "new title of folder";
$f_access = 1;
$newName = TRUE;
$data = array(
'name' => $title,
'access_type' => $f_access
);
if($newName)
{
$data2 = "'icon' => $newName";
array_push($data, $data2);
}
if($password)
{
$data3 = "'password' => $password";
array_push($data, $data3);
}
$this->db->where('id', $fid);
$this->db->update('folders', $data);
你想$ data ['icon'] = $ newName;而不是將此 – ahmad
股票價值推入新數組用於轉換,並使用'array_merge'保留先例索引 –
請閱讀PHP [數組](http://us3.php.net/manual/en/language.types .array.php) –