PHP - Auswahlliste aus einem Array erstellen
<?php
// Auswahlliste aus einem Array erstellen
function select($options = array(), $selected = null) {
$html = '';
if (sizeof($options) > 0) {
$html = '<select>';
foreach($options as $value => $title) {
if ($value === $selected) {
$selectedAttr = ' selected';
} else {
$selectedAttr = '';
}
$html .= '<option value="' . $value . '"' . $selectedAttr . '>' . $title . '</option>';
}
$html .= '</select>';
}
return $html;
}
$options = array(1 => 'Apfel', 2 => 'Birne', 3 => 'Pflaume');
$html = select($options, 2);
?>
Bausteine Alle Anzeigen
Eine zufällige Auswahl von Bausteinen (Codeschnipsel
) aus den Bereichen HTML, CSS,
PHP, JavaScript und MySQL.
<header> Kopfbereich
CSS - Tabellenzeilen einfärben
PHP - Tage zwischen zwei Datumsangaben berechnen
JavaScript - Eine Animation ab einer bestimmten Scroll-Position starten