php - 在while循环PHP中检查数组中的值
问题描述
我有一个返回数组的函数
$statusall = Getstatusall();
数组看起来像这样
$statusall = ['inprogress', 'complete', 'Failed', 'inprogress', 'staring'];
我想循环 Getstatusall 函数,直到所有数组值都“完成”或“失败”我应该如何在 PHP 中执行此操作?
解决方案
此示例回There are values not complete or failed. Repeat.
显,而函数Getstatusall()
返回值不是complete
或的数组failed
。
while( array_diff( Getstatusall(), ['complete', 'failed'] ) ) {
echo "There are values not complete or failed. Repeat.";
// you can even do something else or nothing
}
如果您想获得final result
,这可能会有所帮助:
while( array_diff( $status = Getstatusall(), ['complete', 'failed'] ) ) {
echo "There are values not complete or failed. Repeat."
// you can even do something else or nothing
}
var_dump( $status );
推荐阅读
- reactjs - 删除 Kendo Grid 中的默认分组
- docker - Docker:以非 root 用户身份执行命令
- npm - NPM - 在安装后脚本中使用 CPX 复制文件
- xml - 将标签下的 xml 文件元素与 CSV 文件进行比较,并使用 Powershell 在 CSV 中添加缺失的元素
- c# - 提交按钮有效,但在生产服务器中不显示页面刷新,但在 ITG 服务器和本地服务器中工作正常(使用 c# 的 Asp.net)
- javascript - 如何在 JavaScript 中解开 Promise 的值
- ruby-on-rails - 如何在 shopify 应用程序中创建履行(我的代码有什么问题?)
- jquery - Jquery 切换与引导卡过滤的对齐方式混淆
- redis - Redis 是否具有获取“N 地理上最接近”的功能?
- angular - 当用户未在 Ionic 4 中登录时如何从使用 Id 定义的路由重定向用户