PHP FORM Part-10


 

PHP FORM Part-10

An array is a storage area of multiple values in PHP Program. Where you can add or remove multiple values with the help of array. In simple variable we can store only value at one time but in array variable we can store multiple values.

An array is a storage area of multiple values in PHP Program. Where you can add or remove multiple values with the help of array. In simple variable we can store only value at one time but in array variable we can store multiple values.

Topic : HTML FORM

Part - 10: What is an Array 

An array is a storage area of multiple values. Where you can add or remove multiple values with the help of array. In simple variable we can store only value at one time but in array variable we can store multiple values. 

For example of PHP Form Array : If you have a list of items and you need to do something with them, then it would be quite cumbersome to do this: 

                $Order_1 = "Colors";
                $Order_2 = "Pencil";
                $Order_3 = "Pen";
                $Order_4 = "School Bag";
                $Order_5 = "School Dress";
                $Order_6 = "Shoes";
                $Order_7 = "Shocks";
                $Order_8 = "Water Bottle";
                $Order_9 = "Books";
                $Order_10 = "Notebooks";

What happen if you had not have ten order, Infect you have thousands of order and what happen when you have to run the loop of your orders and search a specific one? Giving name to each variable is not the best programming tool to do here. But an array is! An array can hold all your orders under a single name. And you can access the orders by just referring to the array name. 

Here, we have ten orders and all with a different variable name: $Order_1, $Order_2, $Order_3, $Order_4, $Order_5, $Order_6, $Order_7, $Order_8, $Order_9, $Order_10. 

With the help of an array, we can use only one single name and set up an array. Such as :

                                $Order = array( );

The first thing we need to do is to give name to the array after equals sign. That is :

                                        array( );

It is enough to tell the PHP that you wanted to set up the array for your orders. So, setting up an array just involves writing a word array followed by a parenthesis. But, there we don't have anything in the array and all we have done yet is to set up an array and give it the name $Order.

In the next part of this tutorial, we will learn two basic methods to put something into an array.

Ads