Home » Php » Check values in an array in a while loop PHP

Check values in an array in a while loop PHP

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a function that returns an array

$statusall = Getstatusall();

The array looks like this
this

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

I want to loop the Getstatusall function until all the array values are ‘complete’ or ‘failed’
How should I do that in PHP?

How to&Answers:

This example echo There are values not complete or failed. Repeat. while the function Getstatusall() returns an array with values that are not complete or failed.

while( array_diff( Getstatusall(), ['complete', 'failed'] ) ) {
  echo "There are values not complete or failed. Repeat.";
  // you can even do something else or nothing
}

If you want to get the final result, this may helps:

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 );