我有一个名为$ users的数组,如下所示:
$users = Array
(
[d3c1ac9ac08da86e73258a11a43251af] => enable
[b993166c4795b3bfe96640e55e8dcbbc] => enable
[77d4721ada7677feda77a250c7cee1c4] => disable
[68d6e7a8c09c77c5fec49945beaea4f8] => disable
[85634bc9cdbcb6b39eaf4946b99db5de] => disable
[bb1a20794d65966b950c5933100496ce] => disable
[59ee376a9d126a26b350fff3110ea825] => disable
[428895b1ae5f3226345e6c6f256c7c85] => disable
[78a619902b22a1f17def5198179334be] => disable
[ab5ca5cbfd45c7bd0e0817b200597682] => disable
[2e0ae6cdce7647daf73d3d370a7a12f8] => disable
[867d3433169d05323a4ff350ca21b1c9] => disable
[3dddd9a46cfeb4e4d3607fb178113656] => disable
[ba908fd0f04f245c82ed379bd3f57285] => disable
[ec702094416ad4789288f3f64b3537a7] => disable
[cbb677ed11c1838281c6962d52f62b8a] => disable
[45a1e20492f043d404580becad029f12] => disable
[8b1acc0101378e60985f8200fa3900de] => disable
[f063e4cd1b86f389f2647c4211498615] => disable
[f3639eb674adbb243579942d3746044a] => disable
)
现在我有以下循环:
foreach ($users as $id => $status) {
if($status == disable) { echo "Yes"; die;
$objAdminUsers->UpdateUserStatus($id, $status);
$count++;
}
}
我的问题是,当我逐个遍历数组时,我无法进入if条件。但是当我放入单独的数组元素时,if条件有效并且一切都完美无缺。你能指导我为什么在穿越阵列的时候我无法进入if条件吗?我上面在代码中写的示例消息也没有得到回应。你能帮我这方面吗?提前谢谢。
答案 0 :(得分:0)
1)您从previous/same question复制/粘贴失败。
2)您的$users
数组的值类似_disable
(第一个字符是空格),而不是disable
,这就是您if
语句的原因不管用。用户@AmalMurali已经在你的previous question中写了如何解决这个问题;他甚至粘贴了demo,如:
$array = array_combine($user_ids, $user_statuses);
$array = array_map('trim', $array); // remove whitespaces
3)打开错误报告,这样你就可以看到你的错误。
ini_set('display_errors', 1);
error_reporting(-1);
4)你可能没有定义常量disable
,所以这个:
if ($status == disable) {
无效,如果你有错误报告ON(如第3点所述),你会看到如下通知:
Notice: Use of undefined constant disable - assumed 'disable'