数组foreach未设置下一个键

时间:2014-09-01 02:30:52

标签: php arrays

是否有可能在foreach的过程中取消设置数组的键?例如,我有一个数组和这样的键:

$post = $_POST;
print_r($post);
Array
(
    [proposal] => test
    [proposal_main] => 1-29941
    [ring] => 
    [announcement] => 
    [church] => 
)

现在我的脚本中有这样的东西

foreach($post as $row => $value){

  $sitemap_main = $row.'_main';

  //more process here
  $sitesave[$row] = array(
    'keyword' => $value,
    'insert_timestamp' => date('Y-m-d H:i:s'),
  );

  //get main content for sitemap
  if(isset($post['proposal_main'])){                
    unset($post['proposal_main']);
  }}

 print_r($sitesave);

   [proposal] => Array
    (
        [keyword] => test
        [insert_timestamp] => 2014-09-01 10:58:24
    )

[proposal_main] => Array
    (
        [item_code] => sitemap_royalwedding
        [keyword] => 1-29941
        [insert_timestamp] => 2014-09-01 10:58:24 
    )

[ring] => Array
    (
        [keyword] => 1-29941
        [insert_timestamp] => 2014-09-01 10:58:24
   )

现在我只想取消设置,因为我已经提取了proposalproposal_main的示例数据。不幸的是,当我取消设置密钥时,我仍然存储密钥proposal_main的值。仅供参考:密钥是动态的,可能不像我现在发布的那样排列。

那里有什么好主意吗?或者宁愿评论这是一种糟糕的方法?

0 个答案:

没有答案