Home Tutorial Php Phpbeginning PHP Form Part-13

 
 

Share on Google+Share on Google+
PHP Form Part-13
Posted on: February 26, 2010 at 12:00 AM
Advertisement
In the previous tutorial, we got the enough knowledge how to assign the values in an array. But the question is raise that how to get those values? There are several ways to get those values in the browser. 

Topic : HTML FORM

Part - 13: How to get at the values stored in the arrays. 

In the previous tutorial, we got the enough knowledge how to assign the values in an array. But the question is raise that how to get those values? There are several ways to get those values in the browser. 

Let's see the example below :

<?php

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

    echo $days[0]."<br/>";

    echo $days[1];

?>

And, the output of the above example is : 

Sunday
Monday

The array is the same one we set up before. To get at what is inside of an array, just type the key number you want to access. In the above code, we're printing out what is held in the 0 position (Key) in the array. You just type the key number between the square brackets of your array name:

echo $ArrayName[0];

You can also assign this value to another variable:

$var = $ArrayName[0];
echo $var ;

You can also loop to get the values from an array. Using loop is the lot easier and time saving method of getting values from an array. 

Let's see the example below: 

<?php

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

    for($key=0; $key<7; $key++)

    {

        echo $days[$key]."<br/>";

    }

?>

The output of the above array is : Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

We can access unlimited number of arrays values by using loop. It will save your time and also consume less space on the server.

In the next part of this tutorial, we will learn how to use text for keys instead of numbers.

Advertisement

Related Tags for PHP Form Part-13:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 26, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com