2
我有一個數組$ field。如何將一個函數添加到PHP中的數組中
注意:有人在標籤中添加codeigniter,但問題本身就是關於PHP的。
通常以這種方式保存內容。
// SAVE FORM CONTENTS
foreach ($fields_to_show as $key=>$value) {
$this->CI->preference->set_item($key,$this->CI->input->post($key));
}
這是方法set_item()
function set_item($name, $value)
{
if (is_null($name)) {
return false;
}
$this->preferenceCache[$name] = $value;
if (is_array($value)) {
$value = $this->object_keyword . serialize($value);
}
$this->db->where('name', $name);
return $this->db->update(PREFERENCES, array('value'=>$value));
}
現在場之一是密碼,所以我想編碼。
的方法encode_password()工作正常(我在不同的類使用它),但是當我嘗試以下,但不編碼「ga_password」
// set ga_password
if ($this->CI->input->post('ga_password') != '') {
// Load userlib language
$this->CI->load->module_library('auth','userlib');
$fields_to_show['ga_password'] =
$this->CI->userlib->encode_password($this->CI->input->post('ga_password'));
}
// SAVE FORM CONTENTS
foreach ($fields_to_show as $key=>$value) {
$this->CI->preference->set_item($key,$this->CI->input->post($key));
}