Zdravim.
Tento kod:
Kód:
<?php
$out = '';
$string = 'nieco1,nieco2';
$array_e = explode( ',', $string );
reset( $array_e );
foreach( $array_e as $key => $value ) {
$lastone = next( $array_e ) === FALSE;
$out .= $value;
if( !$lastone ) $out .= '-';
}
echo "\"".$out."\"";
?>
Vypise:
"nieco1nieco2"
Lenze ked tam pridam par riadkov aby to vyzeralo takto:
Kód:
<?php
$out = '';
$string = 'nieco1,nieco2';
$array_e = explode( ',', $string );
reset( $array_e );
$temp = array();
foreach( $array_e as $key => $value ) {
$temp[$key] = $value;
}
$array_e = $temp;
foreach( $array_e as $key => $value ) {
$lastone = next( $array_e ) === FALSE;
$out .= $value;
if( !$lastone ) $out .= '-';
}
echo "\"".$out."\"";
?>
vypise:
"nieco1-nieco2"
Absolutne tomu nechapem, kedze var_dump( $array_e ) vracia v obydvoch pripadoch:
array(2) { [0]=> string(6) "nieco1" [1]=> string(6) "nieco2" }
a current( $array_e ) vracia v obydvoch pripadoch:
nieco1
Mohol by mi to prosim niekto vysvetlit ?
// Inac tiez nerozumiem preco v 2. pripade toto:
Kód:
$lastone = next( $array_e ) === FALSE;
funguje. Podla mna by to malo preskocit kazdu 2. hodnotu. Nasiel som to na nete.