{"id":2479,"date":"2025-04-02T08:00:00","date_gmt":"2025-04-02T06:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=2479"},"modified":"2025-02-28T07:24:23","modified_gmt":"2025-02-28T06:24:23","slug":"php-und-die-switch-anweisung","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2025\/04\/02\/php-und-die-switch-anweisung\/","title":{"rendered":"PHP und die switch-Anweisung"},"content":{"rendered":"\n<p><br>PHP Workshop Nr. 7 macht uns zu Apfelverk\u00e4ufern. Per switch-Anweisung wird ein Formular ausgewertet\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Wenn verschiedene Werte verglichen werden sollen, ist die switch-Anweisung viel praktischer als eine verschachtelte if-Anweisung&#8230; Auch die switch-Anweisung wird auf zwei Webseiten aufgeteilt.<\/p>\n\n\n\n<p><strong>Die Datei \u201cswitch1.php\u201c:<\/strong><\/p>\n\n\n\n<p>Folgendes Formular wird in den ersten Artikel der Webseite eingebaut\u2026:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;form action=\"switch2.php\" method=\"post\" accept-charset=\"utf-8\">\nApfelsorte: \n&lt;br \/>\n&lt;select name=\"apfelsorte\" size=\"1\">\n&lt;option>Jonagold&lt;\/option>\n&lt;option>Delicious&lt;\/option>\n&lt;option>Gala&lt;\/option>\n&lt;option>Elstar&lt;\/option>\n&lt;option>Boskop&lt;\/option>\n&lt;\/select> Bitte w\u00e4hlen Sie eine Apfelsorte aus!\n&lt;br \/>&lt;br \/>\nButtons zum Absenden und Abbrechen:\n&lt;br \/>\n&lt;input type=\"submit\" value=\"Absenden \">\n&lt;input type=\"reset\" value=\"Abbrechen\">\n&lt;br \/>&lt;br \/>\n&lt;\/form><\/code><\/pre>\n\n\n\n<p>Der Nutzer kann hier eine Apfelsorte ausw\u00e4hlen und wenn er auf &#8222;Absenden&#8220; klickt wird auf der zweiten Seite der Preis der ausgew\u00e4hlten Apfelsorte angezeigt.<\/p>\n\n\n\n<p><strong>Die Datei \u201cswitch2.php\u201c:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$sorte = $_POST&#91;\"apfelsorte\"];\necho \"Der Preis f\u00fcr 1kg $sorte betr\u00e4gt...&lt;br \/>\";\nswitch($sorte)\n{\ncase \"Jonagold\":\necho \"1,50 Euro\";\nbreak;\n\ncase \"Delicious\":\necho \"1,60 Euro\";\nbreak;\n\ncase \"Gala\":\necho \"1,70 Euro\";\nbreak;\n\ncase \"Elstar\":\necho \"2,00 Euro\";\nbreak;\n\ncase \"Boskop\":\necho \"2,50 Euro\";\nbreak;\n} \n?><\/code><\/pre>\n\n\n\n<p>F\u00fcr jeden &#8222;case&#8220; wird also eine eigene echo-Anweisung mit anschlie\u00dfendem break ausgegeben. Das muss man nicht bis ins Detail verstehen , sondern nur intelligent anwenden.<\/p>\n\n\n\n<p><strong>Ausblick:<\/strong><\/p>\n\n\n\n<p>Im n\u00e4chsten Teil des PHP Workshops geht es mit der while-Schleife weiter&#8230;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP Workshop Nr. 7 macht uns zu Apfelverk\u00e4ufern. Per switch-Anweisung wird ein Formular ausgewertet\u2026<\/p>\n","protected":false},"author":1,"featured_media":543,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[32],"class_list":["post-2479","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-club","tag-coding-club-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=2479"}],"version-history":[{"count":2,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2479\/revisions"}],"predecessor-version":[{"id":2508,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2479\/revisions\/2508"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/543"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=2479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=2479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=2479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}