gpt4 book ai didi

php - 在foreach循环执行php之前检查条件

转载 作者:行者123 更新时间:2023-11-29 23:44:39 25 4
gpt4 key购买 nike

我想在for循环执行之前检查条件

这是我的数组

$rs=Array (    
[0] => Array (
[questionID] => 47
[surveyID] => 51
[userID] => 31
[question_Title] => Choose Any One?
[question_Type] => Dropdown
[response] => 1.Android 2.Windows 3.Blackberry
[required] => 0
[add_time] => 0
)
[1] => Array (
[questionID] => 48
[surveyID] => 51
[userID] => 31
[question_Title] => Is it?
[question_Type] => Bigbox
[response] => Yes No
[required] => 1
[add_time] => 0
)
[2] => Array (
[questionID] => 129
[surveyID] => 51
[userID] => 31
[question_Title] => sELECT
[question_Type] => Single
[response] => DFG HBK GHCK HK
[required] => 0
[add_time] => 0
)
)

现在我想检查 $rs [required] => 1 中是否存在然后使用 for 每个循环停止所有执行或 $rs 遍历从上面的例子来看,我也想停止执行第一个循环。

最佳答案

使用array_column并实现此功能

引用

低版本数组列函数代码 https://github.com/ramsey/array_column/blob/master/src/array_column.php

 <?php

//assumed records is your array
$required = array_column($records, 'required');


if(FALSE===array_search('1', $required))
{
//value is not exist then process your loop
}
else
{
//required value is 1 then ignore the loop
}

关于php - 在foreach循环执行php之前检查条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26008863/

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