您好我正在尝试从此数组中取消设置数组元素
Array(
[52] => stdClass Object (
[name] => test
[company] => sf
[addr] => sdf
[email] => sdf
[phone] => sdf
[comments] => sdf
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => xx
[enqimg] => xxx
[product_name] => t5
[key] => 52
[action] => new_product
)
)
我在用unset($array['52']);
但它不起作用,但原因不明。
function ajax_new_product(){
$r=(array)json_decode(base64_decode($_COOKIE['products']));
if (isset($_POST['remove']))
{ print_r($r);
unset($r[$_POST['key']+0]);
print_r($r);
}
else
if(is_array($r) && !empty($r))
if (isset ($_POST['key']))
$r[$_POST['key']]=(array)$_POST;
else
$r[]=(array)$_POST;
else
if (isset ($_POST['key']))
$r[$_POST['key']]=(array)$_POST;
else
$r[]=(array)$_POST;
setcookie('products',base64_encode(json_encode($r)),time()+60*60*24*30,"/");
}
这段代码:
if (isset($_POST['remove']))
{ print_r($r);
unset($r[$_POST['key']+0]);
print_r($r);
}
输出
Array
(
[52] => stdClass Object
(
[name] => test
[company] => sf
[addr] => sdf
[email] => sdf
[phone] => sdf
[comments] => sdf
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7503-195x196.jpg
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7503-65x66.jpg
[product_name] => t5
[key] => 52
[action] => new_product
)
[49] => stdClass Object
(
[name] =>
[company] =>
[addr] =>
[email] =>
[phone] =>
[comments] =>
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/ts21-164x196.png
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/ts21-65x66.png
[product_name] => t3
[key] => 49
[action] => new_product
)
[44] => stdClass Object
(
[name] =>
[company] =>
[addr] =>
[email] =>
[phone] =>
[comments] =>
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7501-195x196.jpg
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7501-65x66.jpg
[product_name] => Polo
[key] => 44
[action] => new_product
)
)
Array
(
[52] => stdClass Object
(
[name] => test
[company] => sf
[addr] => sdf
[email] => sdf
[phone] => sdf
[comments] => sdf
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7503-195x196.jpg
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7503-65x66.jpg
[product_name] => t5
[key] => 52
[action] => new_product
)
[49] => stdClass Object
(
[name] =>
[company] =>
[addr] =>
[email] =>
[phone] =>
[comments] =>
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/ts21-164x196.png
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/ts21-65x66.png
[product_name] => t3
[key] => 49
[action] => new_product
)
[44] => stdClass Object
(
[name] =>
[company] =>
[addr] =>
[email] =>
[phone] =>
[comments] =>
[qty] => 150
[date] =>
[brand] => Nike
[quoteimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7501-195x196.jpg
[enqimg] => http://verycreative.info/cristian/custompolos/wp/wp-content/uploads/2012/12/DESIGN_WONT_SAVE_THE_WORLD_TEE_AA_7501-65x66.jpg
[product_name] => Polo
[key] => 44
[action] => new_product
)
)
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/veryinfo/public_html/cristian/custompolos/wp/wp-content/themes/custompolos/functions.php:32) in <b>/home/veryinfo/public_html/cristian/custompolos/wp/wp-content/themes/custompolos/functions.php</b> on line <b>48</b><br />
0