Question: 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:

```
$odd = array(a, c, e, g);

$even = array(b, d, f);

```

Thanks in advance!

Answer: 
I am not sure if this is the most elegant way, but it should work a charm:

```
$odd=array();
$even=array();
$count=1;
foreach($array as $val)
{
    if($count%2==1)
    {
        $odd[]=$val;
    }
    else
    {
        $even[]=$val;
    }
    $count++;
}

```
One more functional solution with array\_chunk and array\_map. The last line removes empty item from the 2nd array, when size of a source array is odd

```
list($odd, $even) = array_map(null, ...array_chunk($ar,2));
if(count($ar) % 2) array_pop($even);

```