Skip to main content
adicionou 124 caracteres ao conteúdo
Fonte Link
rray
  • 67,7mil
  • 21
  • 116
  • 285

$texto = array( 'Ato001_1981', 'Ato002_1980', 'Ato003_1982', 'Ato003_1983', 'Ato004_1982', 'Ato013_1981', 'Ato013_1982', 'Ato013_1988', 'Ato031_1982', 'Ato032_1979', 'Ato039_1988', 'Ato060_1987', 'Ato065_1988', 'Ato066_1988', 'Ato067_1988', 'Ato076_1987', 'Ato077_1988', 'Ato078_1988', 'Ato095_1987', 'Ato137_1987', 'Ato144_1987' );

$new = array(); foreach($texto as $item): $valor = explode('_', $item); $new = ['ano' => $valor[1], 'tipo' => $valor[0]];

$texto = array(
    'Ato001_1981',
    'Ato002_1980',
    'Ato003_1982',
    'Ato003_1983',
    'Ato004_1982',
    'Ato013_1981',
    'Ato013_1982',
    'Ato013_1988',
    'Ato031_1982',
    'Ato032_1979',
    'Ato039_1988',
    'Ato060_1987',
    'Ato065_1988',
    'Ato066_1988',
    'Ato067_1988',
    'Ato076_1987',
    'Ato077_1988',
    'Ato078_1988',
    'Ato095_1987',
    'Ato137_1987',
    'Ato144_1987'
);

$new = array();
foreach($texto as $item):
    $valor = explode('_', $item);
    $new = ['ano' => $valor[1], 'tipo' => $valor[0]];
    
    echo $new['ano'] . '  ' . $new['tipo'] . '<br />';
endforeach;

endforeach;

Aqui funcionou assim.

$texto = array( 'Ato001_1981', 'Ato002_1980', 'Ato003_1982', 'Ato003_1983', 'Ato004_1982', 'Ato013_1981', 'Ato013_1982', 'Ato013_1988', 'Ato031_1982', 'Ato032_1979', 'Ato039_1988', 'Ato060_1987', 'Ato065_1988', 'Ato066_1988', 'Ato067_1988', 'Ato076_1987', 'Ato077_1988', 'Ato078_1988', 'Ato095_1987', 'Ato137_1987', 'Ato144_1987' );

$new = array(); foreach($texto as $item): $valor = explode('_', $item); $new = ['ano' => $valor[1], 'tipo' => $valor[0]];

echo $new['ano'] . '  ' . $new['tipo'] . '<br />';

endforeach;

Aqui funcionou assim.

$texto = array(
    'Ato001_1981',
    'Ato002_1980',
    'Ato003_1982',
    'Ato003_1983',
    'Ato004_1982',
    'Ato013_1981',
    'Ato013_1982',
    'Ato013_1988',
    'Ato031_1982',
    'Ato032_1979',
    'Ato039_1988',
    'Ato060_1987',
    'Ato065_1988',
    'Ato066_1988',
    'Ato067_1988',
    'Ato076_1987',
    'Ato077_1988',
    'Ato078_1988',
    'Ato095_1987',
    'Ato137_1987',
    'Ato144_1987'
);

$new = array();
foreach($texto as $item):
    $valor = explode('_', $item);
    $new = ['ano' => $valor[1], 'tipo' => $valor[0]];
    
    echo $new['ano'] . '  ' . $new['tipo'] . '<br />';
endforeach;

Aqui funcionou assim.

Fonte Link

$texto = array( 'Ato001_1981', 'Ato002_1980', 'Ato003_1982', 'Ato003_1983', 'Ato004_1982', 'Ato013_1981', 'Ato013_1982', 'Ato013_1988', 'Ato031_1982', 'Ato032_1979', 'Ato039_1988', 'Ato060_1987', 'Ato065_1988', 'Ato066_1988', 'Ato067_1988', 'Ato076_1987', 'Ato077_1988', 'Ato078_1988', 'Ato095_1987', 'Ato137_1987', 'Ato144_1987' );

$new = array(); foreach($texto as $item): $valor = explode('_', $item); $new = ['ano' => $valor[1], 'tipo' => $valor[0]];

echo $new['ano'] . '  ' . $new['tipo'] . '<br />';

endforeach;

Aqui funcionou assim.