【发布时间】:2014-02-22 07:04:42
【问题描述】:
我需要能够从插入到 WordPress 选项表中的数组中删除自定义键,这是我使用 print_r 作为回报的数组:
Array (
[customkeyone] => Array (
[itemname] => 'name'
[sortorder] => 1
[date] => 1393042529
[target] => 1
)
[customkeytwo] => Array (
[itemname] => 'nametwo'
[sortorder] => 1
[date] => 1393042525
[target] => 1
)
[customkeythree] => Array (
[itemname] => 'namethree'
[sortorder] => 1
[date] => 1393042522
[target] => 1
)
)
我尝试了不同的方法并且已经接近但无法实际删除/取消设置整个自定义键本身。假设我想取消设置“customkeytwo”,我需要一种方法来传递这个自定义 id 并将其删除:
处理程序示例:
if (isset($_GET['delete'])) {
//ID in this case is "customkeytwo"
if ($_REQUEST['id'] != ''){
$id = $_REQUEST['id'];
$myoptions = get_option('myoptions');
//some method to unset the custom key with $id
//update with new results
update_option('myoptions', $myoptions);
这就是我希望删除后的结果:
Array (
[customkeyone] => Array (
[itemname] => 'name'
[sortorder] => 1
[date] => 1393042529
[target] => 1
)
[customkeythree] => Array (
[itemname] => 'namethree'
[sortorder] => 1
[date] => 1393042522
[target] => 1
)
)
【问题讨论】:
标签: php arrays wordpress multidimensional-array