Repeat Foreach limit

109 Views Asked by At

I have this code

<?php foreach ($column as $k => $v): ?>
    <tr>
       <td><?php echo $v; ?></td>
       <td><?php echo $k; ?></td>
    </tr>
<?php endforeach ?>

And i get this output

<tr>
   <td>id</td>
</tr>
<tr>
   <td>name</td>
</tr>
<tr>
   <td>address</td>
</tr>
<tr>
   <td>birth</td>
</tr>
<tr>
   <td>foto</td>
</tr>

but i don't want to include the foto, how can i do this ?

2

There are 2 best solutions below

0
On BEST ANSWER

you can use if condition inside foreach

<?php foreach ($column as $k => $v): 
    if($v=='foto'){ // skip iteration if value is `foto`
    continue;
    }
?>
                    <tr>
                        <td><?php echo $v; ?></td>
                        <td><?php echo $k; ?></td>
                    </tr>
                <?php endforeach ?>
0
On

You can do the following before starting the loop-

If foto is the key -

if(isset($column['foto']))
    unset($column['foto']);

If foto is value -

if(in_array('foto', $column))
    unset($column[array_search('foto', $column)]);

After that looping starts -

<?php foreach ($column as $k => $v): ?>
    <tr>
       <td><?php echo $v; ?></td>
       <td><?php echo $k; ?></td>
    </tr>
<?php endforeach ?>