首页 > 解决方案 > 在while循环PHP中检查数组中的值

问题描述

我有一个返回数组的函数

$statusall = Getstatusall();

数组看起来像这样

$statusall = ['inprogress', 'complete', 'Failed', 'inprogress', 'staring'];

我想循环 Getstatusall 函数,直到所有数组值都“完成”或“失败”我应该如何在 PHP 中执行此操作?

标签: phparraysloopswhile-loop

解决方案


此示例回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 );

推荐阅读