too long

I have a question i hope someone could help me out here

I have a php array like this

Array
(
    [0] => Array
        (
            [0] => AJP
            [1] => PR4 125 Enduro / SM
            [2] => 125 c.c.
        )
[1] => Array
    (
        [0] => DUCATI
        [1] => YR 125 Desert
        [2] => 125 c.c.
    )

[2] => Array
    (
        [0] => GAS GAS
        [1] => Endurocross TT 80
        [2] => 80 c.c.
    )

[3] => Array
    (
        [0] => GAS GAS
        [1] => EC 125 Six Days 2T
        [2] => 125 c.c.
    )

[4] => Array
    (
        [0] => GAS GAS
        [1] => EC 125 R
        [2] => 125 c.c.
    )

[5] => Array
    (
        [0] => GAS GAS
        [1] => Enducross EC 125
        [2] => 125 c.c.
    )

[6] => Array
    (
        [0] => GAS GAS
        [1] => Enducross HX 125
        [2] => 125 c.c.
    )

[7] => Array
    (
        [0] => GAS GAS
        [1] => Enducross TT 125
        [2] => 125 c.c.
    )

[8] => Array
    (
        [0] => GAS GAS
        [1] => MC 125
        [2] => 125 c.c.
    )

[9] => Array
    (
        [0] => GAS GAS
        [1] => Enducross EC 200
        [2] => 200 c.c.
    )

[10] => Array
    (
        [0] => GAS GAS
        [1] => EC 200 Six Days 2T
        [2] => 200 c.c.
    )

[11] => Array
    (
        [0] => GAS GAS
        [1] => EC 250 2T / EC 250 E 2T
        [2] => 250 c.c.
    )

[12] => Array
    (
        [0] => GAS GAS
        [1] => EC 250 4T / Six Days 2T
        [2] => 250 c.c.
    )

[13] => Array
    (
        [0] => GAS GAS
        [1] => EC 250 4T R / EC 250 R
        [2] => 250 c.c.
    )

[14] => Array
    (
        [0] => GAS GAS
        [1] => Enducross TT 250
        [2] => 250 c.c.
    )

[15] => Array
    (
        [0] => GAS GAS
        [1] => FSE EC 250 4T
        [2] => 250 c.c.
    )

[16] => Array
    (
        [0] => GAS GAS
        [1] => MC 250
        [2] => 250 c.c.
    )

[17] => Array
    (
        [0] => GAS GAS
        [1] => EC 300 / EC 300 Nanbolin
        [2] => 300 c.c.
    )

[18] => Array
    (
        [0] => GAS GAS
        [1] => EC 300 R
        [2] => 300 c.c.
    )

[19] => Array
    (
        [0] => GAS GAS
        [1] => EC 300 Six Days 2T
        [2] => 300 c.c.
    )

[20] => Array
    (
        [0] => GAS GAS
        [1] => Enducross EC 400 FSE
        [2] => 400 c.c.
    )

[21] => Array
    (
        [0] => GAS GAS
        [1] => SM 450 FSR
        [2] => 450 c.c.
    )

[22] => Array
    (
        [0] => GAS GAS
        [1] => Enducross EC 450 FSE
        [2] => 450 c.c.
    )

[23] => Array
    (
        [0] => GAS GAS
        [1] => EC 450 4T R
        [2] => 450 c.c.
    )

[24] => Array
    (
        [0] => GAS GAS
        [1] => FSE 450 SM
        [2] => 450 c.c.
    )

[25] => Array
    (
        [0] => GAS GAS
        [1] => Pampera 450 4T
        [2] => 450 c.c.
    )

[26] => Array
    (
        [0] => GAS GAS
        [1] => EC 515 FSR 4T
        [2] => 515 c.c.
    )

)

I want to format it like

Array
(
    [AJP] => Array
        (
            [1] => PR4 125 Enduro / SM
            [2] => 125 c.c.
        )

[DUCATI] => Array
    (
        [1] => YR 125 Desert
        [2] => 125 c.c.
    )
[GAS GAS] => Array
    (
        [0] => Array
            (
                [1] => EC 125 Six Days 2T
                [2] => 125 c.c.
            )

        [1] => Array
            (
                [1] =>EC 125 Six Days 2T
                [2] => 125 c.c.
            )

        [2] => Array
            (
                [1] => EC 125 Six Days 2T
                [2] => 125 c.c.
            )
    )

) So that The Brand name Like AJP,DUCATI OR GAS GAS becomes the key and all the models in them become multi array.

PHPFiddle: http://phpfiddle.org/main/code/4mi-ap0

$raw = array(
    array('ajp', 1, 2),
    array('ajp', 4, 5),
    array('ducati', 3, 4)
    );

$prep = array();
foreach($raw as $key => $value) {

    $type = $value[0];

    $prep[$type][] = $raw[$key];

    /*if($type === 'ajp') {
        $prep['ajp'][] = $raw[$key];
    }
    else if($type === 'ducati') {
        $prep['ducati'][] = $raw[$key];
    }*/

}

echo '<pre>';
print_r($prep);
echo '</pre>';

Result:

Array
(
    [ajp] => Array
        (
            [0] => Array
                (
                    [0] => ajp
                    [1] => 1
                    [2] => 2
                )

            [1] => Array
                (
                    [0] => ajp
                    [1] => 4
                    [2] => 5
                )

        )

    [ducati] => Array
        (
            [0] => Array
                (
                    [0] => ducati
                    [1] => 3
                    [2] => 4
                )

        )

)

I'm not testing this code; writing on the fly, so there could be a few errors, but here's a rough approximation. Assuming your array is called $arX:

$arNew = array();
foreach ($arX as $x) {
  $newX = array();
  for ($i=1; $i<count($x); $i++) {
     $newX[] = $x[$i];
  }
  $arNew[$x[0]] = $newX;
}
return $arNew;

NOTE: this will actually reindex the new array starting at [0] instead of [1]. If maintaining the order of the new indexes is critical, you'll need to modify the code to use the value of $i in your array, but renumbering at 0 seems to make more sense.

Given $keys = array('a', 'b', 'c', ...) and your array, $list, then do this:

$list = array_combine($keys, array_values($list));

That's nice and simple looking but array_values makes an entire copy of the array so you could have space issues. All we're doing here is letting php do the looping for us, not eliminate the loop. I'd be tempted to do something more like:

foreach ($list as $k => $v) {
unset ($list[$k]);

$new_key =  *some logic here*

$list[$new_key] = $v;
}
$arrNew = array();
foreach ($arrCurr as $arr) {
  $arrTemp = array();

  for ($i=1; $i < count($arr); $i++) {
     $arrTemp[] = $arr[$i];
  }
  $arrNew[$arr[0]][] = $arrTemp;
}
print_r($arrNew);