gpt4 book ai didi

php - 嵌套的 foreach 范围中的 bool 值给出了意外的值

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:38 24 4
gpt4 key购买 nike

我有一个数组数组。他们都是订阅研讨会的人。在表的末尾添加了一些加售产品。问题是:有时有人为 2 个人下订单,并且属于交易的追加销售产品,而不是一个人在两个人之后加入。因此,如果我注册了 2 个人并购买了 2 件衬衫,那么列表会两次显示 2 件衬衫。

所以我想:让我们遍历它,看看我是否找到了一些加售,然后用一个简单的双 foreach 删除每一次出现的事件。但是 $first 的值始终保持 true。虽然它是 false 如果我在声明下方回显它。我重复了几次这些值,并在代码注释中添加了该值。

foreach($results as $key => $result){
if(!empty($result["upsell"])){
$tid = $result["id"];
$first = true;
foreach($results as $result2){
if($result2["id"] == $tid){
// ALWAYS TRUE
if(!$first){
$results[$key]["upsell"] = "";
}
$first = false;
// FALSE
}
}
}
}

这里是否发生了一些奇怪的范围事情?在我看来,它应该先循环并为真,然后再循环并为假。

编辑,添加了结果的 print_r

Array
(
[28] => Array
(
[id] => 1475
[transaction_id] => SAME
[club] => xxxxxxxx
[event] => Voetbalmiddag
[category] => Scoutingdagen
[date_from] => 2017-05-31
[date_end] => 2017-05-31
[first_name] => xxxxxx
[last_name] => xxxxxx
[birth_date] => xxxxxxx
[email] => xxxx@hotmail.com
[address] => xxxxx
[zipcode] => 8xxxxx
[city] => xxxxxx
[phone] => xxxxxx
[soccer_club] => xxxxxxx
[soccer_team] => MP JO7-2
[position] => field
[printed] => 0
[print_name] =>
[print_number] =>
[shirt_size] =>
[sock_size] =>
[pants_size] =>
[referral] => Via de sportvereniging
[comments] =>
[status] => paid
[upsell] => 2 Shirt
)

[29] => Array
(
[id] => 1476
[transaction_id] => SAME
[club] => xxxxxxx
[event] => Voetbalmiddag
[category] => Scoutingdagen
[date_from] => 2017-05-31
[date_end] => 2017-05-31
[first_name] => xxxx
[last_name] => xxxxxxx
[birth_date] => xxxxxxx
[email] => xxxxx@hotmail.com
[address] => Ixxxxx
[zipcode] => xxxxx
[city] => xxxxxx
[phone] => xxxxx
[soccer_club] => xxxxx
[soccer_team] => MP JO9-9
[position] => keeper
[printed] => 0
[print_name] =>
[print_number] =>
[shirt_size] =>
[sock_size] =>
[pants_size] =>
[referral] => Via de sportvereniging
[comments] =>
[status] => paid
[upsell] => 2 Shirt
)

[50] => Array
(
[id] => 1468
[transaction_id] => xxxxxxx
[club] => xxxxxxxxxxx
[event] => Voetbalmiddag
[category] => Scoutingdagen
[date_from] => 2017-05-31
[date_end] => 2017-05-31
[first_name] => xxxxx
[last_name] => xxxxx
[birth_date] => xxxxx
[email] => x@gmail.com
[address] => xxxx 35
[zipcode] => xxxx
[city] => xxxxx
[phone] => xxxxx
[soccer_club] => xxxx
[soccer_team] => jo11-5
[position] => field
[printed] => 0
[print_name] =>
[print_number] =>
[shirt_size] =>
[sock_size] =>
[pants_size] =>
[referral] => Via de flyer
[comments] =>
[status] => open
[upsell] => 1 Shirt
)

)

最佳答案

...
$first = true;
$results1 = $results;
foreach($results1 as $result2){
...

关于php - 嵌套的 foreach 范围中的 bool 值给出了意外的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43977578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com