Codice PHP:
$categoria = array(
'societa di qualcosa',
'societa di qualcosaltro',
'societa all estero',
'professionisti',
'societa specializzate'
);
$categoria_key_temp = array();
for( $i=0,reset( $categoria_array ); list( $key ) = each( $categoria_array ); ++$i ) {
$key = str_replace( " ", "_", $key );
if( in_array( substr( strtoupper( $key ), 0, 4 ), $categoria_key_temp, false ) ) {
$str_array = array();
for( $i=0; $i<strlen( $key ); $i++ ) $str_array[] = $key{$i};
$z=3;
$q=0;
do {
if( !array_key_exists( $z, $str_array ) ) {
$q++;
$z_add = $q;
} else {
$z++;
$z_add = $str_array[$z];
}
$str_check = strtoupper( $str_array[0].$str_array[1].$str_array[2].$z_add );
if( !in_array( $str_check, $categoria_key_temp, false ) ) {
$categoria_key_temp[] = $str_check;
break;
}
if( $z >=30 || $q >=30 ) {
die( "while interrotto a causa di un errore!" );
break;
}
} while( 0 );
} else {
$categoria_key_temp[] = substr( strtoupper( $key ), 0, 4 );
}
unset( $z, $q, $z_add, $str_check, $str_array );
}
Dunque, supponiamo di avere un'array come quello sopra ($categoria):
alla fine nell'array $categoria_key_temp vorrei che sia così formato:
0 => SOCI
1 => SOCE
2 => SOCT
3 => PROF
4 => SOCA
5 => SOCN
In pratica vorrei prendere le prime 4 lettere di ogni elemento del primo array ($categoria);
qualora nell'inserimento nel secondo array ($categoria_key_temp) la voce sia già presente prendo le prime tre lettere + la lettera successiva (fin quando non si verificano le condizioni);
In caso in cui due voci corrispondono perfettamente e non è possibile eseguire lo script uso le prime tre lettere + i numeri da 1 in poi...
qualcuno sa aiutarmi a capire perchè non mi funziona? :master: