fork(2) download
  1. <?php
  2.  
  3. $resultado = array(
  4. array( 'id_serv' => 'carro', 'nm_serv' => '1278' ),
  5. array( 'id_serv' => 'moto' , 'nm_serv' => '2342' ),
  6. array( 'id_serv' => 'carro', 'nm_serv' => '7567' ),
  7. array( 'id_serv' => 'moto' , 'nm_serv' => '5555' ),
  8. array( 'id_serv' => 'moto' , 'nm_serv' => '3335' ),
  9. array( 'id_serv' => 'carro', 'nm_serv' => '6656' ),
  10. array( 'id_serv' => 'carro', 'nm_serv' => '3332' )
  11. );
  12. $saida = array();
  13.  
  14. foreach ($resultado as $res) {
  15. if( !isset( $saida[$res['id_serv']] ) ) {
  16. $saida[$res['id_serv']] = array();
  17. }
  18. array_push( $saida[$res['id_serv']], $res['nm_serv']);
  19. }
  20.  
  21. print_r( $saida );
  22.  
  23. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [carro] => Array
        (
            [0] => 1278
            [1] => 7567
            [2] => 6656
            [3] => 3332
        )

    [moto] => Array
        (
            [0] => 2342
            [1] => 5555
            [2] => 3335
        )

)