samedi 29 avril 2017

PHP Foreach in Foreach with if statement

I am writing a web and i got stuck. PHP is not my language of choice, so I'm not that used to it. But lets look at the problem:

$i = 1;
$n = 0;
<div class="hs_client_logo_slider">
<?php
foreach ($hashone_client_logo_image as $hashone_client_logo_image_single) {
  foreach ($hashone_logo_list as $hashone_logo_url) {       
    if ($i > $n) {
      ?>
      <a target="_blank" href="<?php echo esc_url($hashone_logo_url) ?>"> 
        <img alt="<?php _e('logo','hashone') ?>" src="<?php echo esc_url(wp_get_attachment_url($hashone_client_logo_image_single)); ?>">
      </a>
      <?php
      $n = $n + 1;
      continue 2;
    } else {
        $i = $i + 1;
        continue 1;

Basically I am trying to do:

Foreach (x as y) && Foreach (a as b) {
  /* Magic happens here */

In the first foreach I have images and in the second one links. And for the first image I need the first link stored in logo_list, for the second image I need second link and so on... So I tried If statement that could take care of it, but for some reason it doesn't work.

Now it gives me first image with first link, but every image after that is stuck with second link. Do you have any idea what to do?

I'm glad for everyone who tries to help me out. Thank you very much.

Aucun commentaire:

Enregistrer un commentaire