Can I use ternary in while?

can I use the ternary in the while clause like this?


while (isset($debug) ? $x <=5 : (!feof($csvfile)) {

Did you try?

Syntactically it is valid but you have missed one closing bracket ) there:


while (isset($debug) ? (!feof($csvfile)) : $x <=5) {
    echo $x . '<br />';
    $x++;
}

This works for me.