Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

PHP - foreach() to loop the array values

0 votes
40 views
added Aug 14 in PHP by LC Marshal Captain (25,420 points)
edited Nov 8 by LC Marshal
<?php
  $lc_arr = array(
  array(
    'name'=>'Defender 110',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/defender110',
    'col'=>2
  ),
  array(
    'name'=>'Defender 90',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/defender90',
    'col'=>1
  ),
  array(
    'name'=>'Discovery 1',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/discovery1',
    'col'=>1
  ),
  array(
    'name'=>'Discovery 2',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/discovery2',
    'col'=>1
  ),
  array(
    'name'=>'Range Rover P38',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/rangeroverp38',
    'col'=>1
  ),
  array(
    'name'=>'Defender 130',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/defender130',
    'col'=>1
  ),
  array(
    'name'=>'Defender 110 double cab',
    'desc'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
    'link'=>'http://lc.org/photos/defender110-double-cab',
    'col'=>2
  )
  );
  ?>
  <div class="content_wrapper lc-card row">
  <?php foreach ($lc_arr as $arr):?>
  <a class="lc-cat-card col-<?=$arr['col']?>" href="<?=$arr['link']?>" target="_blank">
    <div class="image" style="background-image:url('https://lazacode.org/public/lcarr/<?=$arr['name']?>.png')">
    <div class="dark-gradient"></div>
    </div>
    <div class="middle">
    <div class="cat-name"><?=$arr['name']?></div>
    <!-- <div class="cat-desc">
      <?=$arr['desc']?>
    </div> -->
    </div>
  </a>
  <?php endforeach;?>
  </div>

 

3 Responses

0 votes
responded Sep 24 by lcjr Sergeant (1,540 points)
//php
<div class="tags">
  <?php foreach($work_types as $i => $work_type): ?>
      <?php print $work_type ?>
  <?php endforeach;?>
</div>
 
//PHP code above rendered HTML output below
<div class="tags">
  <a class="badge" href="#">Walls</a>
  <a class="badge" href="#">Contemporary</a>
  <a class="badge" href="#">Plumbing</a>
  <a class="badge" href="#">Oriental</a>
  <a class="badge" href="#">Modern</a>
</div>

 

0 votes
responded Sep 24 by lcjr Sergeant (1,540 points)
<?php foreach ($services as $item) : ?>
 <div class="col-md-4 col-xs-6">
    <a href="#">
       <i class="fa fa-angle-right" aria-hidden="true"></i><?php print $item->name; ?>
    </a>
 </div>
<?php endforeach;?>

 

0 votes
responded Nov 8 by LC Marshal Captain (25,420 points)
<!--php-->
<div class="tags">
  <?php foreach($work_types as $i => $work_type): ?>
      <?php print $work_type ?>
  <?php endforeach;?>
</div>
 
<!--html-->
<div class="tags">
  <a class="badge" href="#">Walls</a>
  <a class="badge" href="#">Contemporary</a>
  <a class="badge" href="#">Plumbing</a>
  <a class="badge" href="#">Oriental</a>
  <a class="badge" href="#">Modern</a>
</div>
 
<!--example 2-->
<?php foreach ($services as $item) : ?>
 <div class="col-md-4 col-xs-6">
    <a href="#">
       <i class="fa fa-angle-right" aria-hidden="true"></i><?php print $item->name; ?>
    </a>
 </div>
<?php endforeach;?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...