Function

if (!isset($listQueryVideoHit)) $listQueryVideoHit = 0; elseif($listQueryVideoHit === 5) $listQueryVideoHit = 0; 

Now ".(++$listQueryVideoHit)." will lead
1,2,3,4,5
1,2,3,4,5
1,2,3,4,5
1,2,3,4,5
1,2,3,4,5

Need to
1,1,1,1,1
2,2,2,2,2
3,3,3,3,3
4,4,4,4,4
5,5,5,5,5

I tried the spear method, it did not work :(

Thank!

 protected function getcates($nom){ $part = "snippet"; foreach ($wares as $item) { $itemtitle = $item->title; $arr1 = array('XXX'); $arr2 = array(''); $itemtitle=str_replace($arr1, $arr2, $item->title); $item->title=str_replace($arr1, $arr2, $item->title); $itemtitle = preg_replace('/[^\p{L}0-9 \!]/iu', ' ', $itemtitle); $block = ""; $this->url = "https://www.googleapis.com/youtube/v3/search?key="; $data = $this->http(TRUE); foreach ($data->items as $yt) { if (!isset($listQueryVideoHit)) $listQueryVideoHit = 0; elseif($listQueryVideoHit === 5) $listQueryVideoHit = 0; $block .= " <!-- Begin Post --> <article class=\"post-format-".(++$listQueryVideoHit)."> .................... </article> <!-- End Post --> "; } if(!empty($block)){ $html .= '1'.$block.'2'; } } } return $html; } 
  • Show the full code with the cycle in which it all happens - Yaroslav Molchan
  • added code to the question - MicroRu
  • Omg, I recognize this) - vp_arth
  • Yeah, I had to change the template, I ’m finishing it) - MicroRu
  • one
    Please do not delete the code. This is an essential part of the question. - Nick Volynkin

1 answer 1

Take the increment out of the inner loop:

 if (!isset($listQueryVideoHit) || $listQueryVideoHit === 5) $listQueryVideoHit = 0; $listQueryVideoHit++; foreach ($data->items as $yt) { // <article class=\"post-format-".($listQueryVideoHit)."> } 
  • vp_arth, thanks! Works :) - MicroRu