2016-05-11 5 views
0

Ich ziehe einige Informationen aus dem Array, und ich wickle es in Wrapper, so dass alle 6 Elemente in einem Wrapper sind. Dies gibt mir eine Anzahl von Wrappern. Jetzt muss ich Klassen hinzufügen, die basierend auf i+3 Iteration wiederholen. Also brauche ich so etwas haben:Hinzufügen von Klasse auf i + 3 Typ Iteration

<div class="results_wrapper title1"></div> 
<div class="results_wrapper title2"></div> 
<div class="results_wrapper title3"></div> 
<div class="results_wrapper title1"></div> 
<div class="results_wrapper title2"></div> 
<div class="results_wrapper title3"></div> 
<div class="results_wrapper title1"></div> 
<div class="results_wrapper title2"></div> 
<div class="results_wrapper title3"></div> 
<div class="results_wrapper title1"></div> 
<div class="results_wrapper title2"></div> 
<div class="results_wrapper title3"></div> 
<div class="results_wrapper title1"></div> 
<div class="results_wrapper title2"></div> 
<div class="results_wrapper title3"></div> 

Mein aktueller Code ist (unvollständig):

foreach ($tables_completed[$content_count]['table_match'] as $tbm_k => $tbm_v) { 
    $wrap_count = 1; 
    $swipe_title = ''; 
    array_shift($tbm_v); 
    foreach ($tbm_v as $ind_match_k => $ind_match_v) { 
     if($wrap_count % 6 == 1){ 
      if ($wrap_count) { 
       $swipe_title = 'total'; 
      } elseif($wrap_count){ 
       $swipe_title = 'hemma'; 
      } else{ 
       $swipe_title = 'borta'; 
      } 
      $out .= '<div class="results_wrapper'.$swipe_title.'" data-title="'.ucfirst($swipe_title).'">'; 
     } 
     $out .= '<span>'.$ind_match_v.'</span>'; 
     if($wrap_count % 6 == 0){ 
      $out .= '</div>'; 
     } 
     $wrap_count++; 
    } 

} 

Die $tables_completed hat Einträge wie folgt aus:

[1] => Array 
     (
      [table_match] => Array 
       (
        [0] => Array 
         (
          [1] => 2 
          [2] => 2 
          [3] => 0 
          [4] => 0 
          [6] => 9 
          [7] => 6 
          [8] => 1 
          [9] => 1 
          [10] => 0 
          [11] => 0 
          [13] => 5 
          [14] => 3 
          [15] => 1 
          [16] => 1 
          [17] => 0 
          [18] => 0 
          [20] => 4 
          [21] => 3 
         ) 

        [1] => Array 
         (
          [1] => 3 
          [2] => 2 
          [3] => 0 
          [4] => 1 
          [6] => 3 
          [7] => 6 
          [8] => 2 
          [9] => 1 
          [10] => 0 
          [11] => 1 
          [13] => 0 
          [14] => 3 
          [15] => 1 
          [16] => 1 
          [17] => 0 
          [18] => 0 
          [20] => 3 
          [21] => 3 
         ) 

Wrapping funktioniert perfekt, ich Holen Sie sich für jeden Eintrag 6 Zahlen, aber ich muss ihnen wiederholende Klassen hinzufügen, und mein Kopf ist einfach leer.

EDIT

Also in der Theorie sollte diese Arbeit:

<?php 

$i = 1; 

for($i; $i < 14; $i++) { 
    if(($i-2/3) % 3 == 0){ 
     print_r('TRUE for '.$i."\r\n"); 
    } else { 
     print_r('false for '.$i."\r\n"); 
    } 
} 

Also für 1, 4, 7, 10, 13, ... Check

($i-2/3) % 3 == 0 

werden soll, weil das n-te Glied dieser Sequenz ist:

a_n = 3n-2; n= 1, 2, 3, ... 

Ebenso für 2, 5, 8, 11, 14, ... die Formel für das n-te Glied ist

a_n = 3n-1; n= 1, 2, 3, ... 

Das heißt,

($i-1/3) % 3 == 0 

Aber wenn ich mit

if($wrap_count % 6 == 1){ 
    if (($wrap_count-2/3) % 3 == 0) { 
     $swipe_title = 'total'; 
    } elseif(($wrap_count-1/3) % 3 == 0){ 
     $swipe_title = 'hemma'; 
    } else{ 
     $swipe_title = 'borta'; 
    } 
    if ($wrap_count % 18 == 1) { 
     $out .= '<div class="single_match_wrapper"><div class="results_wrapper ' .$swipe_title.'" data-title="'.ucfirst($swipe_title).'">'; 
    } else{ 
     $out .= '<div class="results_wrapper '.$swipe_title.'" data-title="'.ucfirst($swipe_title).'">'; 
    } 
} 

versuchen erhalte ich nur die total aus. Ich habe ein Wrapper um alle 3 kleineren Wrapper, so dass es wie

<div class="single_match_wrapper"> 
    <div class="results_wrapper total" data-title="Total"> 
     <span>2</span><span>2</span><span>0</span><span>0</span><span>9</span><span>6</span> 
    </div> 
    <div class="results_wrapper total" data-title="Total"> 
     <span>1</span><span>1</span><span>0</span><span>0</span><span>5</span><span>3</span> 
    </div> 
    <div class="results_wrapper total" data-title="Total"> 
     <span>1</span><span>1</span><span>0</span><span>0</span><span>4</span><span>3</span> 
    </div> 
</div> 
<div class="single_match_wrapper"></div> 

Die Mathematik Sound ist aussieht, aber die Programmierlogik ist offensichtlich irgendwo defekt ...

Antwort

0

So habe ich

data-num="'.$wrap_count.'" 

zu meiner

$out .= '<div class="results_wrapper '.$swipe_title.'" data-title="'.ucfirst($swipe_title).'">'; 

Und ich immer 1, 7, 13 bekam. Was sinnvoll ist, da ich 6 von ihnen verpacken möchte.

So habe ich gerade:

if ($wrap_count == 1) { 
    $swipe_title = 'total'; 
} 

if ($wrap_count == 7){ 
    $swipe_title = 'hemma'; 
} 

if ($wrap_count == 13) { 
    $swipe_title = 'borta'; 
} 

ich es auch für andere Ergebnisse überprüfen müssen, aber das sollte funktionieren.

Verwandte Themen