0

Hello programmers, the reason you are probably viewing this thread is to learn more about arrays, and PHP itself. Arrays are used throughout all programming languages and not just PHP.
What is an array?
- An array is organization, or an arrangement of choices.
Why are arrays good?
- They provide an easy gathering of data.
- Very easy to benefit.
Now that we know what they are, and why they are good we can create an array of our own!
First we must learn the array structure. Arrays are called by the variable name, and a number.
As you can see "$admins" is an array. To call data out of the array is very easy.PHP Code:$admins[0] = "Outsider";
$admins[1] = "Dave";
$admins[2] = "Drackos";
$admins[3] = "Reaper";
$admins[4] = "Magglas";
Now in the url $i being the data sent. for example you would do this.PHP Code:<?php
$i = $_GET["admin"];
echo "You have picked the administrator, ".$admins[$i]."!";
?>
That would echo (say) "You have picked the administrator, Drackos!";
Note:If you picked a number, that is not in the array, it would not display anything.
How can we use this to our advantage?
Many people have have random music playing. Well how do they do this?
Yep you guessed it. They use an array.
Let's make our basic array setup.
As you can see it randomly selects a value in that array, and plays it when clicked (Thanks JavaPHP Code:$music[0] = "filename.mp3";
$music[1] = "filename.mp3";
$music[2] = "filename.mp3";
$music[3] = "filename.mp3";
$rand = rand( 0, count($music) ); //count function counts number in the array so it can never be higher.
echo "
<p><a href=".$music[$rand].">Play Song</a></p>
<script type='text/javascript' src='http://mediaplayer.yahoo.com/js'></script>
";
)
Now I hope you learned more about arrays, and how to use them to your ability in PHP. This is NBK-DEVASTATION signing off, and good night NGU
Last edited by Jared; 06-19-2012 at 11:51 PM.
Register or log in to view signatures.
Nice tutorial! Dont know much about PHP, but may decide move onto web development after learning Uni-script, C#, and C++. Ive noticed that many of the languages ive seen used are very similar to each other in some ways, if not many ways.
Register or log in to view signatures.
Nice tut, might be hard for the nublets to understand though haha
Register or log in to view signatures.