gpt4 book ai didi

php - 如何通过比较删除特定索引

转载 作者:可可西里 更新时间:2023-10-31 22:50:10 27 4
gpt4 key购买 nike

我想通过比较删除一些索引,但这并不容易

第一个我们的 php 版本是 5例如我的结果是这样的它是由 json_encode 回显的,它是数组并且数据是动态的

[
{
"idx": "1",
"mom_member_idx": "1",
"teacher_member_idx": "2",
"care_start_datetime": "2019-09-09 08:30:00",
},

{
"idx": "2",
"mom_member_idx": "1",
"teacher_member_idx": "2",
"care_start_datetime": "2019-09-10 08:30:00",
},
{
"idx": "3",
"mom_member_idx": "2",
"teacher_member_idx": "2",
"care_start_datetime": "2019-09-09 08:30:00",
}

]

我想得到这样的结果,与最新的比较并取消设置

[
{
"idx": "1",
"mom_member_idx": "1",
"teacher_member_idx": "2",
"care_start_datetime": "2019-09-09 08:30:00",
},
{
"idx": "3",
"mom_member_idx": "2",
"teacher_member_idx": "2",
"care_start_datetime": "2019-09-09 08:30:00",
}

]

我试过了,但是不行

while ($r = mysqli_fetch_assoc($chat_list)) {
$dbdata[] = $r;
}
for($r=0;$r<sizeof($dbdata);$r++){
if ($dbdata[$r]['mom_member_idx']+$dbdata[$r]['teacher_member_idx']==$dbdata[$r+1]['mom_member_idx']+$dbdata[$r+1]['teacher_member_idx'])
{
if($dbdata[$r]['care_start_datetime']<$dbdata[$r+1]['care_start_datetime']){
unset($dbdata[$r]);
}else {
unset($dbdata[$r+1]);
}
}
}

最佳答案

首先,将您的 JSON 数组转换为 PHP 数组。然后你可以使用数组索引删除数组元素

$someArray = json_decode($someJSON, true);

关于php - 如何通过比较删除特定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816131/

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