Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    Location
    St. Helens, England
    Posts
    70
    Member #
    37189
    Liked
    11 times

    PHP Tutorial 5 - Arrays


    This is a follow-up to my previous tutorial: PHP Tutorial 4 - Mathematical Operators. It's wise you should read the last tutorial before you come onto the next one.

    Arrays, like in most programming languages, is to place to store multiple data in one variable.

    So, say, I have a bunch of names of people in my contact list on my phone and I don't want to keep adding loads of variables when it can conveniently stored in one:

    PHP Code:
    <?PHP
    $Array 
    = array("Connor Simpson""Paige Smith""Shannon Boyd");
    ?>
    That's how you do it. But, how do we access it? It's a function after-all and you cant call an array just by echoing the variable. You need to do it a special way.

    The way arrays work is that the first value is number 0, not 1. There's only one programming language I've learnt which doesn't do this (Lua). So to call the first value of the array in my code above you'd type:

    PHP Code:
    <?PHP
    $Array 
    = array("Connor Simpson""Paige Ward""Shannon Boyd");
    echo 
    $Array[0];
    ?>

    Connor Simpson
    If somewhere in your code you'd like to add to an array dynamically you can do:

    PHP Code:
    <?PHP
    $Array 
    = array();
    $Array[] = "I was in the 212";
    echo 
    $Array[0];
    ?>

    I was in the 212
    Each data of an array can also be given a specific name, for instance if you're making a system where it tells you the author of the code:

    PHP Code:
    <?PHP
    $Array 
    = array("Author" => "Connor Simpson""Paige Ward""Shannon Boyd");
    echo 
    $Array['Author'];
    ?>

    Connor Simpson
    It's that easy. Arrays are usually explained in the most hardest way. I hope this tutorial is more narrowed down. Thanks for reading.

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com