<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Magic Book - Free PHP Scripts, Tutorials and Downloads &#187; Switch</title>
	<atom:link href="http://www.phpmagicbook.com/category/switch/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpmagicbook.com</link>
	<description>PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips</description>
	<lastBuildDate>Tue, 15 Jun 2010 13:22:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Switch Statement Examples</title>
		<link>http://www.phpmagicbook.com/switch-examples/</link>
		<comments>http://www.phpmagicbook.com/switch-examples/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 20:01:12 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[Switch]]></category>
		<category><![CDATA[basics]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=154</guid>
		<description><![CDATA[With the use of the switch statement you can check for many conditions at once, and the great thing is that it is actually more efficient programming to do this. A true win-win situation! The way the Switch statement works is it takes a single variable as input and then checks it against all the [...]<p><a href="http://www.phpmagicbook.com/switch-examples/">PHP Switch Statement Examples</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
]]></description>
			<content:encoded><![CDATA[<p>With the use of the switch statement you can check for many conditions at once, and the great thing is that it is actually more efficient programming to do this. A true win-win situation! The way the Switch statement works is it takes a single variable as input and then checks it against all the different cases you set up for that switch statement. Instead of having to check that variable one at a time, as it goes through a bunch of If Statements, the Switch statement only has to check one time.</p>
<p>Consider following examples to understand switch.</p>
<p><span id="more-225"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$v1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Javed&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v2</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Usman&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v3</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Kamran&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$v4</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Azhar&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;Javed&quot;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Javed is a friend&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;Usman&quot;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Usman is working&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;Kamran&quot;</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Kamran is not good&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Nothing to tell you&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// output: Javed is a friend</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$s1</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$s2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$s3</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s1</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ongoing case is 1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ongoing case is 2&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ongoing case is 3&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No Case&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// output: Ongoing case is 1</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Switch Example With Form Input</h4>
<p>Consider<br />
Javed, Usman, Sarfraz, Aubi are friends while Hitler, John and Smith are not.<br />
We have page name as switch_with_form.php<br />
And we have register_globals are on in php.ini<br />
(You can create two pages if you want, one for form and other for script)</p>
<h4>Form Code</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Describe your name for identification:
&lt;form action=&quot;switch_with_form.php&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;name&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;&gt;
&lt;/form&gt;</pre></div></div>

<h4>PHP Code</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;javed&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;usman&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;sarfraz&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;aubi&quot;</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;&lt;font color=blue&gt; Welcome, my dear, <span style="color: #006699; font-weight: bold;">$name</span> ,you are my friend &lt;/font&gt;&lt;/b&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;hitler&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;john&quot;</span><span style="color: #339933;">:</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;smith&quot;</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;&lt;font color=red&gt; Hey, You are no friend of mine, <span style="color: #006699; font-weight: bold;">$name</span> &lt;/font&gt;&lt;/b&gt;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt; I do not know who you are, Mr. <span style="color: #006699; font-weight: bold;">$name</span> , Go away &lt;/b&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Result</h4>
<p>For Aubi, Sarfraz, Usman and Javed input message &#8220;Welcome, my dear, provided name ,you are my friend&#8221; will be appeared and for Hitler, John and Smith a message &#8220;Hey, You are no friend of mine, provided name&#8221; will be appeared.<br />
For any other input third message &#8220;I do not know who you are, Mr. provided name , Go away&#8221; will be displayed.</p>
<p><a href='http://www.phpmagicbook.com/wp-content/uploads/2008/06/switch-examples.rar' class="download">PHP Switch Examples Download</a></p>
<p><a href="http://www.phpmagicbook.com/switch-examples/">PHP Switch Statement Examples</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.phpmagicbook.com/find-page-url-php/" title="Find Page URL With PHP &#8211; File Path">Find Page URL With PHP &#8211; File Path</a></li><li><a href="http://www.phpmagicbook.com/php-string-case-capitalization/" title="PHP &#8211; String Case &#8211; Capitalization">PHP &#8211; String Case &#8211; Capitalization</a></li><li><a href="http://www.phpmagicbook.com/php-post-and-get/" title="PHP Post And Get">PHP Post And Get</a></li><li><a href="http://www.phpmagicbook.com/php-arrays/" title="PHP Arrays">PHP Arrays</a></li><li><a href="http://www.phpmagicbook.com/php-strings/" title="PHP Strings">PHP Strings</a></li><li><a href="http://www.phpmagicbook.com/local-and-glob-scope/" title="Local And Global Variable Scope in PHP">Local And Global Variable Scope in PHP</a></li><li><a href="http://www.phpmagicbook.com/php-logical-operators/" title="PHP Logical Operators">PHP Logical Operators</a></li><li><a href="http://www.phpmagicbook.com/php-functions/" title="PHP Functions">PHP Functions</a></li><li><a href="http://www.phpmagicbook.com/php-for-each-loop/" title="PHP ForEach Loop">PHP ForEach Loop</a></li><li><a href="http://www.phpmagicbook.com/php-do-while-loop/" title="PHP Do While Loop">PHP Do While Loop</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/switch-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quiz &#8211; Switch &#8211; If Else in PHP</title>
		<link>http://www.phpmagicbook.com/quiz-switch-if-else/</link>
		<comments>http://www.phpmagicbook.com/quiz-switch-if-else/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 00:40:41 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[Quiz]]></category>
		<category><![CDATA[Switch]]></category>
		<category><![CDATA[if]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=135</guid>
		<description><![CDATA[Simple quiz using switch and if in PHP. Simple PHP Quiz Using Switch Download Quiz &#8211; Switch &#8211; If Else in PHP is a post from: PHP Magic Book - Free PHP Scripts, Tutorials and Downloads Related PostsAuto Populate Years Range In PHPPHP FunctionsChange Default WordPress Gravatar in CommentsLocal And Global Variable Scope in PHPDownload [...]<p><a href="http://www.phpmagicbook.com/quiz-switch-if-else/">Quiz &#8211; Switch &#8211; If Else in PHP</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Simple quiz using switch and if in PHP.</p>
<p><span id="more-207"></span></p>
<p><a href='http://www.phpmagicbook.com/wp-content/uploads/2008/06/quiz-switch-if.rar' class="download">Simple PHP Quiz Using Switch Download</a></p>
<p><a href="http://www.phpmagicbook.com/quiz-switch-if-else/">Quiz &#8211; Switch &#8211; If Else in PHP</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.phpmagicbook.com/allow-htaccess-and-mod-rewrite-in-wamp/" title="Allow htaccess and Mod Rewrite in Wamp">Allow htaccess and Mod Rewrite in Wamp</a></li><li><a href="http://www.phpmagicbook.com/how-to-include-specific-file-in-wordpress-blog-template/" title="How to Include Specific File In WordPress Blog Template">How to Include Specific File In WordPress Blog Template</a></li><li><a href="http://www.phpmagicbook.com/php-simple-guest-book/" title="PHP Simple Guest-Book">PHP Simple Guest-Book</a></li><li><a href="http://www.phpmagicbook.com/php-file-close/" title="PHP &#8211; File Close">PHP &#8211; File Close</a></li><li><a href="http://www.phpmagicbook.com/php-echo/" title="PHP Echo in PHP">PHP Echo in PHP</a></li><li><a href="http://www.phpmagicbook.com/display-total-number-of-posts-on-your-wordpress-blog/" title="Display Total Number of Posts on Your WordPress Blog">Display Total Number of Posts on Your WordPress Blog</a></li><li><a href="http://www.phpmagicbook.com/display-images-from-folder/" title="Auto Display Images From Folder Using PHP">Auto Display Images From Folder Using PHP</a></li><li><a href="http://www.phpmagicbook.com/get-file-size-and-file-type-in-php/" title="Get File Size and File Type In PHP">Get File Size and File Type In PHP</a></li><li><a href="http://www.phpmagicbook.com/php-email-headers-and-multiple-recipients-html-php-email/" title="PHP eMail &#8211; Headers And Multiple Recipients &#8211; HTML PHP Email">PHP eMail &#8211; Headers And Multiple Recipients &#8211; HTML PHP Email</a></li><li><a href="http://www.phpmagicbook.com/display-the-total-number-of-comments-on-your-wordpress-blog/" title="Display the Total Number of Comments on Your WordPress Blog">Display the Total Number of Comments on Your WordPress Blog</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/quiz-switch-if-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change Color Theme With PHP &#8211; CSS Switch</title>
		<link>http://www.phpmagicbook.com/change-color-theme-with-php-css-switch/</link>
		<comments>http://www.phpmagicbook.com/change-color-theme-with-php-css-switch/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 00:29:47 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Switch]]></category>
		<category><![CDATA[css switch]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=133</guid>
		<description><![CDATA[Concept is to change the CSS file of website for user to give website new color look. It is done by creating a cookie in user&#8217;s system. One switch file, other pages and css files are used in this example. Switch file change CSS applied at website, creates a cookie, saves it and after that [...]<p><a href="http://www.phpmagicbook.com/change-color-theme-with-php-css-switch/">Change Color Theme With PHP &#8211; CSS Switch</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Concept is to change the CSS file of website for user to give website new color look. It is done by creating a cookie in user&#8217;s system.<br />
One switch file, other pages and css files are used in this example. Switch file change CSS applied at website, creates a cookie, saves it and after that redirects the page back at URL from where it was triggered.</p>
<p><span id="more-206"></span></p>
<h4>Switcher.php Code &#8211; Setting Cookie</h4>
<p>[<strong>UPDATE</strong>] Request variable <strong>set</strong> in switcher.php file.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$set</span><span style="color: #339933;">=</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;set&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">setcookie</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sitestyle'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$set</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">31536000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: <span style="color: #006699; font-weight: bold;">$HTTP_REFERER</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>PHP Pages Code For Style Sheets &#038; Links</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;default&quot; href=&quot;&lt;?php echo
(!$sitestyle)?'defaultstyle':$sitestyle ?&gt;.css&quot;&gt;
&lt;link rel=&quot;alternate stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;blue&quot; href=&quot;blue.css&quot;&gt;
&lt;link rel=&quot;alternate stylesheet&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;pink&quot; href=&quot;pink.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href=&quot;switcher.php?set=default&quot;&gt;Default&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;switcher.php?set=blue&quot;&gt;Blue&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;switcher.php?set=pink&quot;&gt;Pink&lt;/a&gt;
&lt;br /&gt;
&lt;a href=&quot;change.php&quot;&gt;page 1&lt;/a&gt; &amp;nbsp;&amp;nbsp; &lt;a href=&quot;change2.php&quot;&gt;page 2&lt;/a&gt;
&lt;/body&gt;</pre></div></div>

<p><a href='http://www.phpmagicbook.com/wp-content/uploads/2008/06/php_css_switcher.rar' class="download">PHP CSS Switcher Download</a></p>
<p><a href="http://www.phpmagicbook.com/change-color-theme-with-php-css-switch/">Change Color Theme With PHP &#8211; CSS Switch</a> is a post from: <a href="http://www.phpmagicbook.com">PHP Magic Book - Free PHP Scripts, Tutorials and Downloads</a></p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.phpmagicbook.com/change-blog-forum-theme-color-scheme-online-live-tool/" title="Change Your Blog or Forum Theme Color Scheme Online Live">Change Your Blog or Forum Theme Color Scheme Online Live</a></li><li><a href="http://www.phpmagicbook.com/change-prosilver-header-logo-phpbb/" title="Change Prosilver Header and Logo in PHPBB &#8211; Working Solution">Change Prosilver Header and Logo in PHPBB &#8211; Working Solution</a></li><li><a href="http://www.phpmagicbook.com/switch-examples/" title="PHP Switch Statement Examples">PHP Switch Statement Examples</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/change-color-theme-with-php-css-switch/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
