Results 1 to 5 of 5

Thread: How to use an Arrays in PHP?

  1. #1
    Join Date
    May 2009
    Posts
    543

    How to use an Arrays in PHP?

    Hi friends,
    I have recently started doing the PHP programming language, so I don't know much about the PHP. Before that I have used arrays but in different programming languages. I don't know how to use it in PHP. So, please tell me how to use an Arrays in PHP? Any coding related to the topic would be much grateful. !!

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What are an Arrays in PHP?

    Since you have used an arrays in other programming languages, I guess that you know why we exactly use it.! An array stores multiple values in one single variable. Using arrays in PHP can be a very powerful technique of handling data. Before knowing about an array, you should know about a variable. A variable is a storage area that holds a number or a text. But the variable holds only one value at a time. Whereas an array is known as a special variable that can store multiple values in one single variable.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Example of an Arrays in PHP?

    You can use the arrays for storing many values. Like, if you are having a list of items, for example lets say, colors, storing the colors in single variables, it will look like :
    PHP Code:
    $color1="Red";
    $color2="Blue";
    $color3="Green"
    Each element in the array has its own index so that it can be easily accessed. An array can hold all your variable values under a single name. And you can access the values by referring to the array name.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Different types of an Arrays in PHP?

    There are three kind of arrays in PHP. They are described as follows :
    • Numeric Array - A numeric array stores each array element with a numeric index. You can create a numeric arrays in two ways :
      1. You can let the index assign automatically.
      2. Or you can assign an index manually.
    • Associative Arrays - Each ID key is associated with a value in an associative array. Its not necessary that numerical array is always best for storing data about specific named values. Many times associative array can be useful. You can use the values as keys and assign values to them by using an associative array.
    • Multidimensional Arrays - In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array. Its very similar like a nested loop, if you consider a loop as an array.

  5. #5
    Join Date
    Mar 2008
    Posts
    672

    Re: Example of an Arrays in PHP?

    Once you have a look on the coding, I think that the things will be clear for you. So I have provided you with an example of an array :
    PHP Code:
    <?php
    $ages
    ['Sam'] = "22";
    $ages['Searu'] = "20";
    $ages['Sweady'] = "24";

    echo 
    "Sam is " $ages['Sam'] . " years old.";
    ?>

Similar Threads

  1. Arrays in C++
    By Acolapissa in forum Software Development
    Replies: 3
    Last Post: 19-12-2010, 10:05 AM
  2. Arrays in C#
    By kavisg1 in forum Software Development
    Replies: 3
    Last Post: 07-10-2010, 07:55 PM
  3. Challenge with Arrays 3d 4d
    By daniel_at_work in forum Software Development
    Replies: 1
    Last Post: 20-08-2010, 10:31 AM
  4. Arrays in C#
    By DotNetUser in forum Guides & Tutorials
    Replies: 2
    Last Post: 03-12-2008, 05:31 PM
  5. Problem with arrays in C++
    By fellah in forum Software Development
    Replies: 3
    Last Post: 05-09-2008, 04:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,545,892.64186 seconds with 16 queries