将_POST值保存到数组中

时间:2022-01-20 01:20:36

I have an array of the names of my POST variables to use when I update a row in my database.

我有一个我在我的数据库中更新行时使用的POST变量名称的数组。

$jobs = array( "proposal_id",
               "will_provide",          
               "general_scope",          
               "per_bid",               
               "job_type");

Using this style my table is called jobs and each value in the array is a column id.

使用此样式,我的表称为作业,数组中的每个值都是列ID。

I want to edit this array so each item (column id) contains a single _POST Value

我想编辑这个数组,所以每个项目(列id)包含一个_POST值

Then I have a function that uses the variables to create generic queries.

然后我有一个使用变量来创建泛型查询的函数。

function save_data($jobs) {

        foreach ($jobs as $job)
        {

          $job[$job[$i]] = _$Post[$job];

              or

          Table_name[column] = cell value;

           ...
           ...
           ...

I would like to be able to save $values into the post variables associated to it. Something like

我希望能够将$值保存到与其关联的post变量中。就像是

For example if I was going to manually create this array it would look like

例如,如果我打算手动创建这个数组,它看起来就像

    $jobs = array('proposal_id' => '12345678','title_of_project' => 'aTitle','creator' => 'aUser','last_modified' => '0000-00-00','date_created' => '0000-00-00','price' =>'1000');

1 个解决方案

#1


1  

This should be what you're looking for:

这应该是你正在寻找的:

$jobs = array( "proposal_id",
               "will_provide",          
               "general_scope",          
               "per_bid",               
               "job_type");

$jobValues = array();
foreach($jobs as $job) {
    $jobValues[] = isset($_POST[$job]) ? $_POST[$job] : null;
}

$jobs = array_combine($jobs, $jobValues);

#1


1  

This should be what you're looking for:

这应该是你正在寻找的:

$jobs = array( "proposal_id",
               "will_provide",          
               "general_scope",          
               "per_bid",               
               "job_type");

$jobValues = array();
foreach($jobs as $job) {
    $jobValues[] = isset($_POST[$job]) ? $_POST[$job] : null;
}

$jobs = array_combine($jobs, $jobValues);