Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Arrays in php

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    Arrays are the sequential memory storage which holds the different elements of same type under a common name.

    The arrays have key/value pair in which the key points to the value.

    There are two types of arrays:

    1. Indexed array and
    2. Associative array.

    Indexed arrays

    The Indexed arrays are the one in which the key are the numeric number which starts with 0 and gets incremented every time a new value inserted in the array.

    The particular element can be pointed by its key index.

    For example:

    $days = array("Monday","Tuesday","Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    

    This can be written as :

    $days[0] = "Monday"; 
    $days[1] = "Tuesday"; 
    $days[2] = "Wednesday";
    $days[3] = "Thursday";
    $days[4] = "Friday";
    $days[5] = "Saturday";
    $days[6] = "Sunday";
    

    Associative Array

    In Associative Array we need to specify the key for each value. the key in the array may be numeric or not, If the key is numeric then it may not be in sequence.

    for example:

    $score = array("Janny"=>80, "Danny"=>90, "John"=>85);
    

    This can be written as :

    $score["Janny"] = 80; 
    $score["Danny"] = 90; 
    $score["John"] = 85; 
    

    Note: The difference between Indexed and Associative array is in the way the key is specified.

    Multidimensional Array

    The Multidimensional Array is the one when we need to store one or more arrays in one array.Like we can store the data from a table in a two-dimensional array.

    lets see an example :

    $colors = array
      (
      array("red",22,18),
      array("blue",15,13),
      array("green",5,2),
      array("white",17,15)
      );
    

    In the above the $colors is a multidimensional which stores the other arrays, to access those array elements we should use two indices to point these, the two indices are the rows and the columns.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: