我对使用数组很新,但我仍然无法删除条目。
如果我有:
$del_itemid = 58;
$del_modiifier = 1;
如何搜索数组$orders
并取消设置包含这些变量的数组?
$orders = Array ( [0] => Array ( [itemid] => 67 [modifier] => 1 [quantity] => 1 [unit_price] => 17.00 [categoryid] => 2 ) [1] => Array ( [itemid] => 58 [modifier] => 1 [quantity] => 1 [unit_price] => 18.00 [categoryid] => 5 ) [2] => Array ( [itemid] => 72 [modifier] => 1 [quantity] => 1 [unit_price] => 10.00 [categoryid] => 3 ) )
修改
这就是我一直在尝试的:
$i = 0;
foreach($orders as $key => $value) {
$itemid = $value['itemid'];
$modifier = $value['modifier'];
if ($itemid == $del_itemid && $modifier == $del_modifier) {
unset($_SESSION['cart'][$i]);
break;
}
$i++;
}
答案 0 :(得分:2)
Since you want to check 2 values, I would use array_filter()
将活动css类应用于li,以循环遍历数组并过滤所有subArrays,其中两个值均等于您的搜索价值观,例如
File file = new File(filePath);
final FileInputStream fileInputStream = new FileInputStream(file);
byte fileContent[] = new byte[(int) file.length()]; //***BOMBS HERE***
fileInputStream.read(fileContent);
fileInputStream.close();
Asset programDataAsset = Asset.createFromBytes(fileContent);
答案 1 :(得分:0)
我找到了一个基于我最初尝试通过循环实现的解决方案。如果我使用array_splice()
而不是unset()
,它将重置索引,以便仍然可以循环遍历数组,而不会在索引中出现漏洞:
$i = 0;
foreach($orders as $key => $value) {
$itemid = $value['itemid'];
$modifier = $value['modifier'];
if ($itemid == $del_itemid && $modifier == $del_modifier) {
array_splice($orders, $i,1);
}
$i++;
}