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

后端 未结 9 645
旧时难觅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:09

    as @VisioN said it would be easier if you use associative array or else you can have a separated array of labels while iterating on the client side

    var d=["Hello.mp3", "00:00:14", "Byebye.mp3", "00:00:30", "Whatsup.mp3", "00:00:07", "Goodnight.mp3", "00:00:19"] ;
    var e=["name","time"];
    var c=0;
    $.each(d,function(i,j){
        if(c>=2)c=0;
        console.log(e[c]+j);
        c++;
    });
    

    http://jsfiddle.net/FmLYk/1/

提交回复
热议问题