fork download
  1. <?php
  2. $arrayCategorias = array(
  3. array('1-6'),
  4. array('1-7'),
  5. array('2-9'),
  6. array('3-2'),
  7. array('3-5'),
  8. );
  9. $newArr = array();
  10. foreach($arrayCategorias as $key => $val) {
  11. $exp = explode('-', $val[0]);
  12. $newArr[$exp[0]][] = $val[0];
  13. }
  14.  
  15. echo '<pre>', print_r($newArr), '</pre>';
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [1] => Array
        (
            [0] => 1-6
            [1] => 1-7
        )

    [2] => Array
        (
            [0] => 2-9
        )

    [3] => Array
        (
            [0] => 3-2
            [1] => 3-5
        )

)
1</pre>