<?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>Computer Training - Video Tutorials &#187; PHP</title>
	<atom:link href="http://www.talentedpixel.com/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.talentedpixel.com</link>
	<description>Create without Limits</description>
	<lastBuildDate>Mon, 23 Aug 2010 21:22:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Beginners PHP Tutorial &#8211; Arrays and Web Forms Part 3</title>
		<link>http://www.talentedpixel.com/php/beginners-php-tutorial-arrays-and-web-forms.html</link>
		<comments>http://www.talentedpixel.com/php/beginners-php-tutorial-arrays-and-web-forms.html#comments</comments>
		<pubDate>Mon, 03 Nov 2008 12:10:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[beginners php tutorials]]></category>

		<guid isPermaLink="false">http://www.talentedpixel.com/?p=341</guid>
		<description><![CDATA[
 High Quality PHP Tutorial Videos &#8211; Taught by Experts
We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly
Title / Free Demo : Beginners PHP  Tutorial Videos
Author: Mike Morton
Duration: 6 Hours &#8211; Lessons: 86
PHP Arrays and HTML Forms &#8211; Part 3.
PHP Arrays [...]]]></description>
			<content:encoded><![CDATA[<div style="margin:10px;border:1px #666666 dashed;padding:10px;">
<p><img style="float:left;margin:0px 10px 0px 10px;" src="http://www.computer-training-software.com/images/2titles-pic-dual.jpg" alt="" width="118" height="122" /> <strong>High Quality PHP Tutorial Videos &#8211; Taught by Experts<br />
</strong>We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly<strong><br />
Title / Free Demo :</strong> <a href="http://www.computer-training-software.com/php-basic.htm">Beginners PHP  Tutorial Videos</a><strong><br />
Author:</strong> Mike Morton<strong><br />
Duration:</strong> 6 Hours<strong> &#8211; Lessons:</strong> 86</div>
<h3>PHP Arrays and HTML Forms &#8211; Part 3.</h3>
<h4>PHP Arrays and HTML Forms</h4>
<p><em>This beginners PHP tutorial covers creating Arrays &#8211; Suitable for all versions of PHP</em></p>
<p>This is tutorial #3 in our Array Series.  Today you’ll learn how to collect data from a web form and convert it into an  array for further processing on the backend.</p>
<p>Why would you need to create an array from a web form? Good question and here  is a good answer!</p>
<p><strong>What would you like on that Pizza, sir?</strong></p>
<p>Let’s look at a simple web form for a pizza  shop that provides online ordering. We’ll skip over the parts of the form that  collects name and address, etc., and go right for the meat (and cheese) of the  problem.</p>
<p><img src="http://www.computer-training-software.com/manuels/images-php03/clip_image002.jpg" alt="" width="320" height="219" /></p>
<p>The form above allows the user to select  the pizza size from a drop-down containing the values Large, Medium, and Small.  Nothing special going on there. We name that drop-down “size”, and use the  built-in ‘option value’ field to add all of the sizes. In the <em>code view</em>,  it would look like this:</p>
<pre class="php">&lt;select name="select"&gt;
       &lt;option&gt;-- Select --&lt;/option&gt;
        &lt;option value="Large"&gt;Large&lt;/option&gt;
        &lt;option value="Medium"&gt;Medium&lt;/option&gt;
        &lt;option&gt;Small&lt;/option&gt;
 &lt;/select&gt;</pre>
<p>The real magic happens when we get to the  add-on ingredients. Because we want the user to be able to select multiple  ingredients, radio buttons were not an option. That’s because radio buttons use  a simple off/on methodology. If you have multiple radio buttons in a group,  radio buttons are not an option.</p>
<p>We could have used a multi-select drop-down  list. That’s the type of drop-down where you can press and hold the Ctrl key  while selecting multiple options, but that solution can be difficult for users  to grasp. So, the checkbox is the right choice. It allows the user to select  multiple options by simply click on each ingredient choice.</p>
<p>Normally, a checkbox looks like this when  in code view:<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;SomeName&#8221; value=&#8221;SomeValue&#8221; /&gt;</p>
<p>If you wanted to have multiple checkboxes to support our ingredients list, you <em>could</em> create them like this:</p>
<p class="style3">&lt;input type=&#8221;checkbox&#8221; name=&#8221;Cheese&#8221; value=&#8221;xtracheese&#8221; /&gt;<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;SomeName1&#8243; value=&#8221;pepperoni&#8221; /&gt;<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;SomeName2&#8243; value=&#8221;sausage&#8221; /&gt;<br />
&lt;input type=&#8221;checkbox&#8221; name=&#8221;SomeName3&#8243; value=&#8221;onions&#8221; /&gt;</p>
<p>But that wouldn’t be a very efficient way  to do it. Why? Because you would have to write code on the backend using a lot  of “if” statements to loop through each variable to see if it was checked.  That’s not very efficient.</p>
<h3>PHP Arrays to the rescue</h3>
<p>By simply altering the way we name each  checkbox slightly, we can have the HTML form create an array and pass it to our  backend processing script.</p>
<pre class="php">&lt;input type="checkbox" name="options[ ]" value="xtracheese" /&gt;
&lt;input type="checkbox" name="options[ ]" value="pepperoni" /&gt;
&lt;input type="checkbox" name="options[ ]" value="sausage" /&gt;
&lt;input type="checkbox" name="options[ ]" value="onions" /&gt;
</pre>
<p>Do you see the difference between this  example and the one above it? Look carefully.<br />
Notice that all of the checkboxes have the  same name value. They are all called ‘options’. Now, there is nothing special  about the name. We could have called them all ‘ingredients’, or anything else  for that matter. The real magic is the square brackets [ ] that we added <em>after</em> the name.</p>
<p>These brackets tell PHP that we are passing  it an array and that multiple values may exist. If we had eliminated those  brackets, and simply created four checkboxes all with the same name, PHP would  only recognize the checked value of the first checkbox it processed. The  additional ingredient choices would be lost.</p>
<h4>Processing that pizza order</h4>
<p>So now that you have that array of choices  passed to your backend script, what do you do with them? You already now the  answer. You simply process it using the <em>foreach</em> function that you  already learned.</p>
<p>Depending upon whether your form uses the <em>get</em> or the <em>post</em> method, your array is in the $_POST or the $_GET array.  Let’s assume $_POST for this example.</p>
<p class="style3">foreach($_POST[‘options’] as $ingredients) {</p>
<p class="style3">&lt; add your own processing here&gt;;</p>
<p class="style3">}</p>
<p>Lets give it a try, create a HTML page and paste the following code in between the &lt;body&gt; tags:</p>
<pre class="php">&lt;form id="form1" name="form1" method="post" action="pizza-process.php"&gt;
&lt;strong&gt;Papa's Famous Pizza&lt;/strong&gt;

&lt;select name="size"&gt;
&lt;option&gt;-- Select --&lt;/option&gt;
&lt;option value="Large"&gt;Large&lt;/option&gt;
&lt;option value="Medium"&gt;Medium&lt;/option&gt;
&lt;option&gt;Small&lt;/option&gt;
&lt;/select&gt;

What would you like on that Pizza, sir?

&lt;input type="checkbox" name="options[ ]" value="xtracheese" /&gt;
Extra Cheese
&lt;input type="checkbox" name="options[ ]" value="pepperoni" /&gt;
Pepperoni
&lt;input type="checkbox" name="options[ ]" value="sausage" /&gt;
Sausage
&lt;input type="checkbox" name="options[ ]" value="onions" /&gt;
Onions

&lt;input type="submit" name="button" id="button" value="Order Your Pizza" /&gt;

&lt;/form&gt;</pre>
<p>Create a PHP page and call it pizza-process.php, paste the following code into the PHP file :</p>
<pre class="php">&lt;?php
  echo "I would like a  $_POST[size] Pizza ";
// find what extras are required
  foreach($_POST[options] as $ingredients) {
echo"With $ingredients ";
} 

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.talentedpixel.com/php/beginners-php-tutorial-arrays-and-web-forms.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beginners Flash Tutorial &#8211; Working with MYSQL and PHP</title>
		<link>http://www.talentedpixel.com/flash/beginners-flash-tutorial-working-with-mysql-and-php.html</link>
		<comments>http://www.talentedpixel.com/flash/beginners-flash-tutorial-working-with-mysql-and-php.html#comments</comments>
		<pubDate>Thu, 30 Oct 2008 14:14:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash Tutorials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php tutorials]]></category>

		<guid isPermaLink="false">http://www.talentedpixel.com/?p=273</guid>
		<description><![CDATA[
 High Quality &#8211; Flash Tutorial Videos &#8211; Taught by experts.
We also have extensive Adobe Flash Tutorials in high quality video format. These are ideal for beginners who need to master Flash quickly
Title / Free Demo : Adobe Flash  CS3 Tutorial Videos
Author: James Gonzalez
Duration: 11 Hours &#8211; Lessons: 125
Flash with PHP / MySQL
The code [...]]]></description>
			<content:encoded><![CDATA[<div style="margin:10px;border:1px #666666 dashed;padding:10px;">
<p><img style="float:left;margin:0px 10px 0px 10px;" src="http://www.computer-training-software.com/images/2titles-pic-dual.jpg" alt="" width="118" height="122" /> <strong>High Quality &#8211; Flash Tutorial Videos &#8211; Taught by experts.</strong><br />
We also have extensive Adobe Flash Tutorials in high quality video format. These are ideal for beginners who need to master Flash quickly</p>
<p><strong>Title / Free Demo :</strong> <a href="http://www.computer-training-software.com/adobe-flash-cs3.htm">Adobe Flash  CS3 Tutorial Videos</a><strong><br />
Author:</strong> James Gonzalez<strong><br />
Duration:</strong> 11 Hours<strong> &#8211; Lessons:</strong> 125</div>
<h3>Flash with PHP / MySQL</h3>
<p><img style="float:left;margin:0px 10px 0px 5px;" src="http://talentedpixel.com/wp-content/themes/revolution_music-10/images/flash.jpg" alt="" /><em>The code used in this tutorial is mainly ActionScript 2.0, with notes for using ActionScript 3.0 &#8211; basic knowledge of databases (particularly MySQL) and server-side scripting concepts is assumed, for users who require an a tutorial on Beginners PHP and MySQL we recomend the <a href="http://www.computer-training-software.com/php-basic.htm">Beginners PHP Training Video</a></em></p>
<p>Given that Flash is used primarily on the Web, database driven components are a common requirement. In order to use data in this way within your Flash movies, you will need to use some sort of server-side scripting language, such as PHP. We use server-side scripting to communicate with a data source on the server, and Flash has some built-in capabilities for handling the data at the client-side.</p>
<p>To demonstrate, we will create a simple database-driven Flash movie using PHP and MySQL. <em>This example will need to be deployed on a server with PHP and MySQL installed.</em></p>
<p>In MySQL, create a database called &#8216;flashtest&#8217;, with one table in it called &#8216;flashdata&#8217;; in the table create just one field (for simplicity &#8211; the details of the database are not important), name the field &#8216;flash_text&#8217; and choose VARCHAR as the data type. Enter a few rows of data into the table, any strings of text will be fine.</p>
<p>Now we need PHP code to connect to and query your database. Create a file called get_data.php in the directory you intend to put your Flash file in &#8211; this will need to be on the same server as the MySQL database for the following code to work. In get_data.php enter the following code (replacing username and password with your own):</p>
<p><a class="highlighttext" onclick="fnSelect('select1')" href="javascript:void(0);">Select All</a></p>
<pre id="select1" class="php">&lt;?php

//connect to the local MySQL
mysql_connect("localhost", "username", "password");

//select your database
mysql_select_db("flashtest");

//query the database
$query="select * from flashdata";
$result=mysql_query($query);

//find out how many entries there are
$num=mysql_num_rows($result);

//write variable out - this is what the Flash document will retreive
echo "&amp;num=".$num;

//keep count
$count=0;

//loop through and write the data into variables for the flash document
while($row=mysql_fetch_array($result))
{
   //write out each entry as a variable
    $entry=$row["flash_text"];
    echo "&amp;t".$count."=".$entry;
    //increment the count variable
    $count++;
}

?&gt;</pre>
<p><em>Tip: you can test your PHP at this stage by fetching get_data.php in a Web browser &#8211; it should look something like this:</em><br />
<img title="php test" src="http://talentedpixel.com/wp-content/themes/revolution_music-10/images/phptest.jpg" alt="php test" /></p>
<p>Now to use the data within a Flash movie, create a new Flash document and save it on the server also. The Flash document is able to access the variables written out by your PHP script via the GET variable. Open the Actions panel for Layer 1 and enter the following code (replacing &#8216;filepath&#8217; with the path to your PHP script):</p>
<p><a class="highlighttext" onclick="fnSelect('select2')" href="javascript:void(0);">Select All</a></p>
<pre id="select2" class="php">      //load the variables into a MovieClip by calling the server-side script
var data_mc:MovieClip=_root.createEmptyMovieClip("data_mc", _root.getNextHighestDepth());
     //loadVariables parameters: url, movieclip, method
loadVariables("http://localhost/filepath/get_data.php", data_mc, "GET");

    //create the function for using the data
data_mc.onData=function()
{
    //get the total number of entries
    var numEntries:Number=data_mc.num;
      //loop through the entries
   for(var i:Number=0; i</pre>
<p>Now test your movie, it should look something like this:<br />
<img title="output" src="http://talentedpixel.com/wp-content/themes/revolution_music-10/images/output.jpg" alt="output" width="353" height="244" /></p>
<p>For Flash MX and above, you can alternatively use the LoadVars object with the following syntax:</p>
<p><a class="highlighttext" onclick="fnSelect('select3')" href="javascript:void(0);">Select All</a></p>
<pre id="select3" class="php">//create LoadVars object
var lv:LoadVars=new LoadVars();
//load the data
lv.load("http://localhost/filepath/get_data.php");
//setup load function
lv.onLoad=function(success)
{
//get the data
var numEntries:Number=lv.num;
//otherwise syntax is the same as above
};</pre>
<p>If you&#8217;re using ActionScript 3.0, the syntax will be slightly different; you need to use the URLRequest and URLLoader objects to load the data into Flash.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talentedpixel.com/flash/beginners-flash-tutorial-working-with-mysql-and-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Tutorials &#8211; Arrays Part 2</title>
		<link>http://www.talentedpixel.com/php/beginners-php-tutorials-arrays-part-2.html</link>
		<comments>http://www.talentedpixel.com/php/beginners-php-tutorials-arrays-part-2.html#comments</comments>
		<pubDate>Mon, 20 Oct 2008 20:37:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Recent Tutorials]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[beginners php tutorials]]></category>

		<guid isPermaLink="false">http://www.talentedpixel.com/?p=215</guid>
		<description><![CDATA[

 High Quality PHP Tutorial Videos &#8211; Taught by Experts
We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly
Title / Free Demo : Beginners PHP  Tutorial Videos
Author: Mike Morton
Duration: 6 Hours &#8211; Lessons: 86
Advanced PHP Arrays
This tutorial covers creating Arrays &#8211; Suitable [...]]]></description>
			<content:encoded><![CDATA[<div style="clear:both;"></div>
<div style="margin:10px;border:1px #666666 dashed;padding:10px;">
<p><img style="float:left;margin:0px 10px 0px 10px;" src="http://www.computer-training-software.com/images/2titles-pic-dual.jpg" alt="" width="118" height="122" /> <strong>High Quality PHP Tutorial Videos &#8211; Taught by Experts<br />
</strong>We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly<strong><br />
Title / Free Demo :</strong> <a href="http://www.computer-training-software.com/php-basic.htm">Beginners PHP  Tutorial Videos</a><strong><br />
Author:</strong> Mike Morton<strong><br />
Duration:</strong> 6 Hours<strong> &#8211; Lessons:</strong> 86</div>
<h3>Advanced PHP Arrays</h3>
<p><em>This tutorial covers creating Arrays &#8211; Suitable for all versions of PHP</em></p>
<p>Don’t let the word <em>advanced</em> worry  you. You are simply <em>advancing</em> along in your knowledge about how to use  these amazing data structures.</p>
<p>Arrays are like tables in that they have <em>columns</em> and rows. And, thanks to the array functions PHP makes available, they can be  manipulated like tables in many ways.</p>
<p>In the introduction to <a href="http://www.talentedpixel.com/php/php-tutorials-arrays-part-1.html">PHP Arrays tutorial</a> ,  you learned about how to create <em>indexed</em> and <em>associative</em> arrays. I  wrote that arrays were powerful tools, especially when combined with the <em>foreach</em> function and with the other functions designed especially for manipulating the data within arrays.</p>
<p>In this lesson, I’ll show you some practical  uses for arrays and how to get them working their hardest for you.</p>
<h4>Displaying All Elements in an Array</h4>
<p>In the previous tutorial we created these  two arrays:</p>
<p class="style3">$mystaff  = array(0=&gt;’Matthew’,<br />
1=&gt;’Mark’,<br />
2=&gt;’Luke’);</p>
<p class="style3">$salaries=array(&#8220;Matthew&#8221;=&gt;65000,<br />
&#8220;Mark&#8221;=&gt;75000,<br />
&#8220;Luke&#8221;=&gt;100000);</p>
<p>Let’s create an array that lets us store  the staff member’s name and salary together. Then we’ll use PHP’s <em>foreach</em> function to display them.</p>
<p class="style3">$mystaff[‘Matthew’]=65000;<br />
$mystaff[‘Mark’]=75000;<br />
$mystaff[‘Luke’]=100000;</p>
<p>This array structure may look odd, but all  we have done is to create an associative array and use the name of each staff  member as the <em>key</em>.</p>
<p>This is a great little trick that will play  right into the hands of the <em>foreach</em> loop below. We’ll look at the syntax  first and then I’ll explain the logic.</p>
<h4>Foreach Syntax</h4>
<p class="style3">foreach(  $mystaff as $Name =&gt; $salary){<br />
echo &#8220;Name: $Name, Salary: $ $salary  &#8220;;<br />
}</p>
<p class="style3">Name:  Matthew, Salary: $65000<br />
Name:  Mark, Salary: $75000<br />
Name:  Luke, Salary: $10000</p>
<p><strong>How It Works</strong></p>
<p>The <em>foreach</em> statement above  translates to this:</p>
<p>For each element of the $mystaff associative  array I want to call the key by the name of $Name and the value that’s related  to that key by the name $salary.</p>
<p>Then I want to print each of those values,  one set at a time, until I reach the end of the array.</p>
<p>The <em>foreach</em> statement I provided  uses the <em>as</em> modifier, and the <em>as</em> modifier uses the “=&gt;”  operator. Just think of this as a finger pointing from the key to the value.</p>
<p>Create a new PHP document and name it foreach.php. Copy the code below into the document and upload it to your web server and open the page in a browser.</p>
<p><a class="highlighttext" onclick="fnSelect('select877443')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select877443" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Arrays&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php   $mystaff[‘Matthew’]=65000;   $mystaff[‘Mark’]=75000;
$mystaff[‘Luke’]=100000;   foreach( $mystaff as $Name =&gt; $salary){
 echo "Name: $Name, Salary: $ $salary ";   }
echo 'I have '. count($mystaff). ' Staff members.';   ?&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<h4>PHP Array Functions</h4>
<p>Here are examples of how PHP array-specific  functions provide quick ways to enhance the power of arrays in your PHP  programs.</p>
<h4>Counting Array Elements</h4>
<p>Count() returns the number of elements in  an array. Use the Count() function to see how many staff members there are.</p>
<p class="style3">echo ‘I have ’. count($mystaff). ’  Staff members.’;</p>
<h4>Sorting Array Elements</h4>
<p>To sort the names alphabetically before  displaying them, use the asort() function.</p>
<p class="style3">asort($mystaff);</p>
<h4>Array Element Math</h4>
<p>To calculate the total payroll for your  staff, use the array_sum() function.</p>
<p class="style3">Echo ‘The total salary paid to my ‘ .count($mystaff). ’ Staff  members =’ . array_sum($mystaff).’’;</p>
<h4>Adding Array Elements</h4>
<p>You could add a new employee quickly using  the array_push() function.</p>
<p class="style3">array_push($mystaff[‘John’],  55000);</p>
<p>John would be added to the end of the  array. Calling asort(), after array_push(), would alphabetize the array properly.</p>
<h4>Deleting Array Elements</h4>
<p>If John was hired to replace Matthew, the  unset function would send Matthew to the unemployment line and asort() would  restore the array’s sorted order.</p>
<p class="style3">unset($mystaff[‘Matthew’]);<br />
asort($mystaff);</p>
<h4>Tutorial Summary</h4>
<p>These are just a few of the 75 functions  PHP makes available for working with arrays. You can find the entire list,  along with their syntax, by visiting PHP’s online <a rel="nofollow" href="http://us.php.net/manual/en/ref.array.php">Array Function Manual</a>. If you would like to learn more about PHP and Arrays we offer a extremely comprehensive <a href="http://www.computer-training-software.com/php-basic.htm">PHP video tutorial</a> that offers indepth, step-by-step instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talentedpixel.com/php/beginners-php-tutorials-arrays-part-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Tutorials &#8211; Arrays Part 1</title>
		<link>http://www.talentedpixel.com/php/php-tutorials-arrays-part-1.html</link>
		<comments>http://www.talentedpixel.com/php/php-tutorials-arrays-part-1.html#comments</comments>
		<pubDate>Mon, 20 Oct 2008 20:21:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Recent Tutorials]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[beginners php]]></category>
		<category><![CDATA[php tutorials]]></category>

		<guid isPermaLink="false">http://www.talentedpixel.com/?p=212</guid>
		<description><![CDATA[

 High Quality PHP Tutorial Videos &#8211; Taught by Experts
We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly
Title / Free Demo : Beginners PHP  Tutorial Videos
Author: Mike Morton
Duration: 6 Hours &#8211; Lessons: 86
PHP Arrays &#8211; Basics
This tutorial covers creating Arrays &#8211; [...]]]></description>
			<content:encoded><![CDATA[<div style="clear:both;"></div>
<div style="margin:10px;border:1px #666666 dashed;padding:10px;">
<p><img style="float:left;margin:0px 10px 0px 10px;" src="http://www.computer-training-software.com/images/2titles-pic-dual.jpg" alt="" width="118" height="122" /> <strong>High Quality PHP Tutorial Videos &#8211; Taught by Experts<br />
</strong>We also have extensive PHP Tutorials in high quality video format. These are ideal for beginners who need to master PHP quickly<strong><br />
Title / Free Demo :</strong> <a href="http://www.computer-training-software.com/php-basic.htm">Beginners PHP  Tutorial Videos</a><strong><br />
Author:</strong> Mike Morton<strong><br />
Duration:</strong> 6 Hours<strong> &#8211; Lessons:</strong> 86</div>
<h3>PHP Arrays &#8211; Basics<em></em></h3>
<p><em>This tutorial covers creating Arrays &#8211; Suitable for all versions of PHP</em></p>
<h3>Introduction to the PHP Array</h3>
<p>The <em>array</em> data  structure provides a convenient way to store multiple values in a single  variable.  An Array uses pointers or  index keys to map each value stored within it. The type of pointer, and the  syntax for accessing it, varies depending upon the array <em>type </em>used.  An array is permitted to store other arrays as  values. Here is a look at both of PHP’s array types and how they are created  and used.</p>
<p>Indexed Array<br />
An <em>indexed</em> array uses integers  as the key. The Array index begins at 0. PHP imposes no limit on the maximum  number of elements an array may contain, so there is no maximum ending integer.  Of course, array size is subject to the memory limitations established in  the PHP.ini file as well as of the server where PHP is running.</p>
<h3>Associative Array</h3>
<p><em>Associative</em> arrays use string values as  keys.</p>
<p><strong>Creating an Indexed Array</strong></p>
<p>An  array can be created simply by storing a value to a variable that uses the  array structure.</p>
<p><strong>Example:</strong></p>
<p><strong></strong><br />
<a class="highlighttext" onclick="fnSelect('select1')" href="javascript:void(0);">Select All</a></p>
<pre id="select1" class="php">$mystaff[0]=’Matthew’;</pre>
<p>The  above method creates an <em>indexed array</em>. This method is often used when  the array will be built with values that can not be pre-determined or that will  be created on the fly.</p>
<p>If the  values of the array are known ahead of time, you could use this syntax:</p>
<p><strong>Example:</strong></p>
<p><strong></strong><br />
<a class="highlighttext" onclick="fnSelect('select87775433')" href="javascript:void(0);">Select All</a></p>
<pre id="select87775433" class="php">$mystaff = array(0=&gt;’Matthew’, 1=&gt;’Mark’, 2=&gt;’Luke’);</pre>
<p>In the  above example, the array has <em>3</em> elements, even though the last element’s  key is the integer 2. New PHP programmers may forget the indexed array key  structure is zero-based, hence the 3rd element in the above example is referanced by 2 and not 3.</p>
<p>Both  indexed array creation methods are  interchangeable. You do not have to use one method under any particular  circumstance.</p>
<p><strong>Displaying an Indexed Array</strong></p>
<p>The value of an indexed array  element is displayed by referencing the array element by its key.</p>
<p><strong>Example:</strong><br />
<a class="highlighttext" onclick="fnSelect('select988542')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select988542" class="php">echo "The names of my three staff members are:
$mystaff[0] . ", " . $mystaff[1] . ", " . $mystaff[2];</pre>
<p>Give it a try, create a new document enter the following code</p>
<p><a class="highlighttext" onclick="fnSelect('select23459945')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select23459945" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Arrays&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php   $mystaff = array(0=&gt;’Matthew’,   1=&gt;’Mark’,   2=&gt;’Luke’);
 &lt;p&gt;echo "The names of my three staff members are: ".   $mystaff[0] . ",
" . $mystaff[1] . ", " . $mystaff[2]; ?&gt;
&lt;/body&gt; &lt;/html&gt;</pre>
<p>&gt;and save it as array-test.php, upload it to your web server and view it.</p>
<p><strong>Creating an Associative Array</strong></p>
<p>An <em>associative</em> array  uses a string value as the key. Where an <em>indexed</em> array is typically used  to store strings, an <em>associative</em> array is typicall<em>y</em> used to store  numeric values. However, it is entirely up to you which array type you use.  These are guidelines, not rules.</p>
<p>In this example below, we will  create an <em>associative </em>array containing salary information for those three  staff members we created in the <em>indexed array</em> example above.</p>
<p><strong>Example</strong></p>
<pre>$salaries["Matthew"] = 65000;
$salaries["Mark"] = 75000;
$salaries["Luke"] = 100000;</pre>
<p>Instead of  declaring each array value on its own line, you could also use this syntax:</p>
<p><a class="highlighttext" onclick="fnSelect('select738294572')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select738294572" class="php">$salaries=array("Matthew"=&gt;65000, "Mark"=&gt;75000, "Luke"=&gt;100000);</pre>
<p>Displaying an Associative Array<br />
<a class="highlighttext" onclick="fnSelect('select7384378')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select7384378" class="php">echo "Matthew’s salary is: $" . $salaries["Matthew"] . "". "Mark’s salary is:
$" . $salaries["Mark"] . "".
"Luke’s salary is: $" . $salaries["Luke"];</pre>
<p>Give it a try, delete the contents of your array-test.php page and replace it with the follow:<br />
<a class="highlighttext" onclick="fnSelect('select738543372')" href="javascript:void(0);"><br />
Select All</a></p>
<pre id="select738543372" class="php">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;head&gt;
&lt;meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Arrays&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php   $salaries=array("Matthew"=&gt;65000,   "Mark"=&gt;75000,
"Luke"=&gt;100000); echo "Matthew’s salary is: $" . $salaries["Matthew"] . "".
 "Mark’s salary is: $" . $salaries["Mark"] . "".
  "Luke’s salary is: $" . $salaries["Luke"]; ?&gt;
&lt;/body&gt;   &lt;/html&gt;</pre>
<p>After saving your page, upload to your webserver and view. You know have a fundamental knowledge of creating and displaying Arrays in PHP.</p>
<p><strong>Summary</strong></p>
<p>Arrays  are powerful tools, especially when used with the <em>for</em> and <em>while</em> functions. There are other PHP functions designed especially for working with  arrays. They provide convenient methods for sorting, transversing, and manipulating  arrays. We’ll look at these in next PHP Array tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talentedpixel.com/php/php-tutorials-arrays-part-1.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

