Close



Keep me logged in.

Forgot your password? | Register Now

Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12
  1. Original Post
    [move]Jake from state farm.[/move] 402 Crew!
    Jake625's Avatar

    Default Arrays, and How to use

    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.

    PHP Code:
    $admins[0] = "Outsider";
    $admins[1] = "Dave";
    $admins[2] = "Drackos";
    $admins[3] = "Reaper";
    $admins[4] = "Magglas"
    As you can see "$admins" is an array. To call data out of the array is very easy.

    PHP Code:
    <?php
    $i 
    $_GET["admin"];
    echo 
    "You have picked the administrator, ".$admins[$i]."!";
    ?>
    Now in the url $i being the data sent. for example you would do this.


    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.

    PHP Code:
    $music[0] = "filename.mp3";
    $music[1] = "filename.mp3";
    $music[2] = "filename.mp3";
    $music[3] = "filename.mp3";
    $rand rand0count($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>
    "

    As you can see it randomly selects a value in that array, and plays it when clicked (Thanks Java )




    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.

  2. The Following 8 Users Say Thank You to Jake625 For This Useful Post:

    caleb01 (04-24-2012), Convex (04-15-2012), Just4Hax (04-15-2012), Lord Hal (04-15-2012), Merkii (04-15-2012), Mr. Bean (04-15-2012), Shadoh (04-15-2012), X_GIXXER_X (04-15-2012)

  3. #11
    Skilled Typer
    caleb01's Avatar

    Default





    0 Not allowed! Not allowed!
    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.

  4. #12
    Ragdoll

    Default


    0 Not allowed! Not allowed!
    Nice tut, might be hard for the nublets to understand though haha
    Register or log in to view signatures.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •