Split array into two arrays by index even or odd

前端 未结 10 2110
执笔经年
执笔经年 2020-11-30 12:37

I have this array:

$array = array(a, b, c, d, e, f, g);

I want to split it in two arrays depending if the index is even or odd, like this:<

10条回答
  •  执念已碎
    2020-11-30 12:44

         Even: ";
    
    foreach ($array1 as $print) 
    {
        if ($count%2==1) 
        {
            $evenarray = $print;
            echo "$print";
        }
        $count++;
    }
    
    echo "
    Odd: "; foreach ($array1 as $print2) { if ($count%2!=1) { $oddarray[] = $print2; echo "$print2"; } $count++; } ?> Output: Original: 0123456789 Even: 02468 Odd: 13579

提交回复
热议问题