gpt4 book ai didi

php - 如何检查多维数组中的数组键?

转载 作者:可可西里 更新时间:2023-10-31 23:28:02 24 4
gpt4 key购买 nike

如何检查数组键是否存在于数组中?

我需要检查数组中是否存在用户 ID,我找到了下面的数组,

 Array
(

[0] => Array
(
[user_id] => 1482309797
[week] => 1
[type] => 1
[commission] => 4000
)

[1] => Array
(
[user_id] => 1482309797
[week] => 1
[type] => 1
[commission] => 0
)

[2] => Array
(
[user_id] => 1482309797
[week] => 1
[type] => 1
[commission] => 4000
)

[3] => Array
(
[user_id] => 1482309797
[week] => 1
[type] => 1
[commission] => 0
)

[4] => Array
(
[user_id] => 1483096072
[week] => 1
[type] => 1
[commission] => 4000
)

[5] => Array
(
[user_id] => 1483333245
[week] => 1
[type] => 1
[commission] => 2000
)

)

我想检查用户id是否存在,我试过下面的代码

        foreach ($com_array as $report) {

$user_id=$report['user_id'];

if(array_key_exists($user_id,$output_array)){
echo "Eid found";
}else{
echo "id not found";
}

}

任何人请帮助。

最佳答案

  foreach ($com_array as $report) {
if(isset($report['user_id'])){
echo "Eid found";
}else{
echo "id not found";
}
}

尝试上面的代码,你会得到输出。

关于php - 如何检查多维数组中的数组键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41627432/

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