Php 从会话数组中删除值

Php 从会话数组中删除值,php,arrays,session,Php,Arrays,Session,如何使用表中的删除链接从会话数组中删除值 //归档 < ?php $_SESSION['cart']['prices'][] = "1000"; $_SESSION['cart']['services'][] = "game 1"; $_SESSION['cart']['prices'][] = "2000"; $_SESSION['cart']['services'][] = "game 2"; $_SESSION['cart']['prices'][] = "3000"; $_SESS

如何使用表中的删除链接从会话数组中删除值

//归档

< ?php
$_SESSION['cart']['prices'][] = "1000";
$_SESSION['cart']['services'][] = "game 1";
$_SESSION['cart']['prices'][] = "2000";
$_SESSION['cart']['services'][] = "game 2";
$_SESSION['cart']['prices'][] = "3000";
$_SESSION['cart']['services'][] = "game 3";
$_SESSION['cart']['prices'][] = "4000";
$_SESSION['cart']['services'][] = "game 4";
?>
<?php
$\u会话['cart']['prices'][]=“1000”;
$\会话['cart']['services'][]=“游戏1”;
$\会话['cart']['prices'][]=“2000”;
$\会话['cart']['services'][]=“游戏2”;
$\会话['cart']['prices'][]=“3000”;
$\会话['cart']['services'][]=“游戏3”;
$\会话['cart']['prices'][]=“4000”;
$\会话['cart']['services'][]=“游戏4”;
?>
//在文件B中

< table border="1">
< thead>
< th style="width: 450px; text-align:center;">Services< /th>
< th style="width: 450px; text-align:center;">Price< /th>
< th style="width: 450px; text-align:center;">Delete item< /th>
< /thead>
< tbody>
< ?php
foreach ($_SESSION['cart']['services'] as $key => $service) {
    echo "< tr>< td>".$service."< /td>< td style='text-align:center;'>".$_SESSION['cart']['prices'][$key]."< /td>< td>ckick to remove< /td>< /tr>";
}
?>
< /tbody>
< /table>

服务
价格
删除项目

<?php
foreach($\会话['cart']['services']作为$key=>$service){
echo“”;
}
?>
”$service。”>“$\u会话['cart']['prices'][$key]。”单击以删除“
使用
unset()
重置会话值:

unset($_SESSION['cart']['services']);

尝试使用“unset()”?例如
unset($\u会话['cart']['services'])更好
取消设置($_会话['cart']['services'][$indexToRemove])但我想删除特定的服务和价格。怎么可能呢?“只需使用
$\u SESSION['cart']['services'][$index]=null
取消设置($_会话['cart']['services'])