for example I will write $data = [ok,ok,ok,ok,ok] I would like to echo "ok"
but if $data = [ok,ok,ok,not,ok] I would like to echo "not ok"
I need help.
Count if all values are 'ok'.
$data = ['ok', 'ok', 'ok', 'ok', 'ok'];
echo count(array_filter($data, fn($v) => $v !== 'ok')) ? 'not ok' : 'ok', PHP_EOL;
$data = ['ok', 'ok', 'ok', 'not', 'ok'];
echo count(array_filter($data, fn($v) => $v !== 'ok')) ? 'not ok' : 'ok', PHP_EOL;
echoes
ok
not ok
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.