Looping through array and output as pairs (divider for each second element)

后端 未结 9 530
旧时难觅i
旧时难觅i 2021-01-18 03:41

I have an array with anonymous elements. Elements are added to the array via php, like so:

$playlist = array();

while (databaseloop) {
  $playlist[] = $a_ti         


        
9条回答
  •  迷失自我
    2021-01-18 04:03

    A simple for loop with an increment of two. You might want to make sure that your array length is long enough for i+1, in case the length isn't divisible by 2!

    for (i = 0; i+1 < array.length; i+=2) {
      name = array[i];
      length = array[i+1];
    }
    

提交回复
热议问题