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++;
}

```
Based on @Jon's second variant, I made this following **for use with PHP Smarty v3 template engine**. This is for displaying news/blog with both one or two columns template model.

After the MySql query I'll do the following code :

```
if(sizeof($results) > 0) {
    $data = array();
    foreach($results as $k => $res) {
        if($k % 2 == 0) {
            $res["class"] = "even";
            $data["all"][] = $data["even"][] = $res;
        }
        else {
            $res["class"] = "odd";
            $data["all"][] = $data["odd"][] = $res;
        }
    }
}

```

I obtain an array of 3 sub-arrays (including odd/even class) with Smarty syntax of use :

1. all items `{foreach $data.all as $article}...{/foreach}`
2. odd items only `{foreach $data.odd as $article}...{/foreach}`
3. even items only `{foreach $data.even as $article}...{/foreach}`

Hope it helps some people...