-4

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 ?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98

2 Answers2

1

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 ?>
Jigar Shah
  • 6,143
  • 2
  • 28
  • 41
Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
0

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 ?>
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87