There is an array

Array ( [0] => aaaaaa [1] => IN/123 [2] => bbbbbb [3] => /IN/124 ) 

How to get it to work:

aaaaaa - IN / 123

bbbbbb - / IN / 124

In the for loop and increasing the counter by +1 for the second element?

    2 answers 2

     $chunks = array_chunk($your_array, 2); foreach ($chunks as $chunk) { echo implode('-', $chunk); } 
    • That is why js doesn’t have such convenient functions, and there are a lot of them in pkhp?) - Ilya Zelenko
     for ($i = 0; $i < count($data); $i +=2) echo $data[$i] . ' - ' . $data[$i + 1];