How to start foreach loop with triple condition

I have two foreach loops to display some data, but I want to use one foreach based on the database result.

means that if any row is returned from the database, then it forach($first as $fk=>$fv)must be executed otherwise it foreach($other as $ok)must be executed. im unsing below ternary operator that gives parsing error

$n=$db->numRows($taskData); // databsse results

<?php ($n) ? foreach ($first as $fk=>$fv) : foreach ($other as $ok) 
{ ?>
<table><tr><td>......some data...</td></tr></table>
<?php } ?>

please suggest me how to handle this state with the ternary operator or any other idea.

thank

+3
source share
1 answer

, $fv , $ok .

foreach ( ($n ? $first : $other) as $fk => $fv )

, , , , , $n, $fk, $fv $ok.

- , , , , ?

+4

Source: https://habr.com/ru/post/1738659/


All Articles