<?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; for</title>
	<atom:link href="http://www.phpmagicbook.com/tag/for/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</generator>
		<item>
		<title>Get Data As An Array &#8211; Download PHP Example</title>
		<link>http://www.phpmagicbook.com/get-data-as-an-array-download-php-example/</link>
		<comments>http://www.phpmagicbook.com/get-data-as-an-array-download-php-example/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 18:38:22 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[Arrays]]></category>
		<category><![CDATA[For Loop]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[Loops]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=167</guid>
		<description><![CDATA[Array &#038; Loop Example Suppose we have a form and we want from user to select from a list of check boxes and check his favorite choices, post that data as an array and we want to display that data by calling array and arranging it in a loop. Then for this purpose consider following [...]<p><a href="http://www.phpmagicbook.com/get-data-as-an-array-download-php-example/">Get Data As An Array &#8211; Download PHP Example</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[<h4>Array &#038; Loop Example</h4>
<p>Suppose we have a form and we want from user to select from a list of check boxes and check his favorite choices, post that data as an array and we want to display that data by calling array and arranging it in a loop. Then for this purpose consider following example.</p>
<p><span id="more-237"></span></p>
<h4>Form Code</h4>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p&gt;Arrays example&lt;/p&gt;
&lt;p&gt;Check your favorite Movies:
&lt;/p&gt;
&lt;form action=&quot;nextpagename.php&quot; method=&quot;post&quot; name=&quot;array-form&quot; id=&quot;array-form&quot;&gt;
  &lt;p&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;Harry Potter&quot;&gt;
    Harry Potter&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;The Hobbit&quot;&gt;
    The Hobbit&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;Lord Of Rings&quot;&gt;
    Lord Of Rings&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;Matrix&quot;&gt;
    Matrix&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;Happy Feet&quot;&gt;
    Happy Feet&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;The Hell Boy&quot;&gt;
    The Hell Boy&lt;br /&gt;
    &lt;input name=&quot;pick[]&quot; type=&quot;checkbox&quot; value=&quot;Hulk&quot;&gt;
    Hulk&lt;/p&gt;
  &lt;p&gt;
    &lt;label&gt;
    &lt;input type=&quot;submit&quot; name=&quot;button&quot; id=&quot;button&quot; value=&quot;Submit&quot;&gt;
    &lt;/label&gt;
&lt;/p&gt;
&lt;/form&gt;</pre></div></div>

<h4>PHP Code &#8211; Retrieve Data From Array and Display It Through A Loop</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pick'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$displaydata</span><span style="color: #339933;">=</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pick'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$displaydata</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In the above example we have collected the data from check boxes in form of arrays named as <strong>pick[]</strong> and we have sent it to another PHP page where it is displayed through a for loop.</p>
<p><a href='http://www.phpmagicbook.com/wp-content/uploads/2008/06/array-example.rar' class="download">PHP Arrays Example Download</a></p>
<p><a href="http://www.phpmagicbook.com/get-data-as-an-array-download-php-example/">Get Data As An Array &#8211; Download PHP Example</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/php-for-loop/" title="PHP For Loop">PHP For Loop</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-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><li><a href="http://www.phpmagicbook.com/php-while-loop/" title="PHP While Loop">PHP While Loop</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/get-data-as-an-array-download-php-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP For Loop</title>
		<link>http://www.phpmagicbook.com/php-for-loop/</link>
		<comments>http://www.phpmagicbook.com/php-for-loop/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 19:46:11 +0000</pubDate>
		<dc:creator>Hiroshi</dc:creator>
				<category><![CDATA[For Loop]]></category>
		<category><![CDATA[Loops]]></category>
		<category><![CDATA[PHP Basics]]></category>
		<category><![CDATA[basics]]></category>
		<category><![CDATA[for]]></category>

		<guid isPermaLink="false">http://www.phpmagicbook.com/?p=158</guid>
		<description><![CDATA[For loop consists of three phases. i.e. Define Condition Increment or decrement First we define something. Then we apply a condition and then under that condition we increment or decrement that defined thing. In complex way; - The first part is an expression that is evaluated once when the loop begins. - The second part [...]<p><a href="http://www.phpmagicbook.com/php-for-loop/">PHP For Loop</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>For loop consists of three phases. i.e.</p>
<ul>
<li>Define</li>
<li>Condition</li>
<li>Increment or decrement</li>
</ul>
<p>First we define something. Then we apply a condition and then under that condition we increment or decrement that defined thing.</p>
<p>In complex way;<br />
- The first part is an expression that is evaluated once when the loop begins.<br />
- The second part is the condition. While the condition is true, the loop continues repeating. If the condition is false to start with, the following code block is not executed at all.<br />
- The third part is an expression that is evaluated once at the end of each pass of the loop.</p>
<p><span id="more-228"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">for ( initialize a counter;
       conditional statement;
       increment a counter)
{
	do this code;
}</pre></div></div>

<h4>Examples</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 12345678910</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Explanation of above example:</span>
<span style="color: #666666; font-style: italic;">// In this we define a var i and give it a value of 1.</span>
<span style="color: #666666; font-style: italic;">// We tell the script to increment the value of i and print it.</span>
<span style="color: #666666; font-style: italic;">// And keep incrementing it and printing it until it reaches to the value of 10.</span>
<span style="color: #666666; font-style: italic;">// Or keep incrementing it and printing it if it is less then 10 or equal to 10.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Caution:</span>
<span style="color: #666666; font-style: italic;">// Now do not run a loop without a condition.</span>
<span style="color: #666666; font-style: italic;">// Because it can go pretty mad without a condition.</span>
<span style="color: #666666; font-style: italic;">// and go in cyclic chain process which will never end.</span>
<span style="color: #666666; font-style: italic;">// and your PC or at least your PHP host will be held.</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Other Examples Of For Loop In PHP</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 12345678910</span>
&nbsp;
<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;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> <span style="color: #339933;">;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 12345678910</span>
&nbsp;
<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: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 12345678910</span>
&nbsp;
<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: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$num</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$num</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 1 2 3 4 6 7 8 9</span>
&nbsp;
<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: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$num</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span> <span style="color: #000088;">$num</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Output of this script will be. 1 2 3 4</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Using PHP for loop allows you to use much less code to do the same thing as with while and do.</p>
<p><a href="http://www.phpmagicbook.com/php-for-loop/">PHP For Loop</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/get-data-as-an-array-download-php-example/" title="Get Data As An Array &#8211; Download PHP Example">Get Data As An Array &#8211; Download PHP Example</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><li><a href="http://www.phpmagicbook.com/php-while-loop/" title="PHP While Loop">PHP While Loop</a></li><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></ul>]]></content:encoded>
			<wfw:commentRss>http://www.phpmagicbook.com/php-for-loop/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
