【发布时间】:2016-06-23 18:17:47
【问题描述】:
我正在学习 PHP 并在 Codeigniter 中工作。当我制作数据数组并声明函数所需的变量时,我觉得我在重复输入类似的内容(重复工作)。
这是一个例子:
//MAKE ARRAY OF USER ANSWERS TO QUESTIONS
$dropdowndata = array
( 'user_socialhour' => $this->input->post('socialhour'),
'user_socialpm' => $this->input->post('socialpm'),
'user_eventhour' => $this->input->post('eventhour'),
'user_eventpm' => $this->input->post('eventpm');
//DECLARE THE VARIABLES I NEED FOR FUNCTIONS
$user_socialhour = $this->input->post('socialhour');
$user_socialpm = $this->input->post('socialpm');
$user_eventhour = $this->input->post('eventhour');
$user_eventpm = $this->input->post('eventpm');
$calculateddata = array
('user_mornafteve' => $this->mornafteve($user_socialhour, >$user_socialpm), 'user_beforeafter' => $this->beforeafter($user_socialpm, >$user_eventpm, $user_socialhour, $user_eventhour));
我正在寻找一种方法来自动声明 dropdowndata 数组中的所有变量。我正在寻找类似的东西,对于每个键,根据以下模式声明变量。
这存在吗?
【问题讨论】:
标签: php arrays codeigniter object variable-declaration