The array is a different variable that can store various values.
In other words,
The array is a special type of variable that can contain various variables. The array can contain a lot of values in a list.
Definition and use of Array
The array is the collection of similar data items. The array is used for the same data types.
Array a kind of data structure that can store a fixed-size sequential collection of
elements of the same data type
Array removes the data complexity.
The array() function can contain multiple values.
Syntax of Array
array("value1", "value2 ", "value3");
In the above syntax of an array, we have declared an array() function with multiples values. The array can be defined as the database structure for values. You can store values in a list
.In above syntax , you can see an array() function contained value1 , value 2 and value 3.
Examples of Array
In these examples, we will declare the array function.
$fruits = array("Banana", "Mango ", "Orange");
echo "I like " . $fruits . ", " . $fruits . " and " . $fruits . ".";
In the above example, we declared an array of fruits variable. We used some of the fruits items as values. The index number is must in array. The index number initialized from the 0.
array("Banana(0 index value )", "Mango(1 index value ) ", "Orange(2 index value )");
Banana is stored at 0 index value , manago is stored at 1 index value and orange is stored at index numer 2.
Sometimes we get out of our mind that the array index number starts from 0. If you think the array starts with an index number 1,
then this is absolutely wrong. Keep in mind that the array index number starts from number 0.
If you get an incorrect array index number, you will get an error. Array index always starts from 0.
$fruits ----- Zero index number of an array .
$fruits ----- Index number one of an array .
$fruits ----- Index number two of an array .
If you have a list of items (a list of fruit names, for example), store the fruits in single variables could look like this:
Let's have another array example. In this example, we will declare the array one by one with the index number and its values.
It's another way to declare array and store in a variable. It is known as an
We can define the index value one by one and print them like below example.
Sr No <?php echo"$x";
Sr No <?php echo "$x";
Sr No <?php echo "$x";
Sr No <?php echo "$x";
In the above array example, we declared the array one by one. The $x is an array variable or name.
In the first example, we used the variable once and we did not give any array index number but in this example, we have defined different values with its index number.
So this is different from the first example.
$first_odd_number = $odd_no;
$second_odd_number = $odd_no;
$third_odd_number = $odd_no;
$fourth_odd_number = $odd_no;
echo "This is first odd number = $first_odd_number";
echo "This is second odd number = $second_odd_number";
echo "This is third odd number = $third_odd_number";
echo "This is fourth odd number = $fourth_odd_number";
This is first odd number = 1
This is second odd number = 3
This is third odd number = 5
This is fourth odd number = 7
In this above example, we created an array which has taken the odd number. As you know, the odd numbers start 1,3,5,7,9, etc.
An odd number is the meaning of which does not have to be completely divided by 2.
Odd number divides by same odd number.
9 divides by 9 and 1 divides by 1 .
After that, we have stored different index values of the array in another variable. The variables are -
1.$first_odd_number - First variable stored 0 index value
2.$second_odd_number -second variable stored 0 index value
3.$third_odd_number -Third variable stored 0 index value
4.$fourth_odd_number- Fourth variable stored 0 index value
After that, we have printed the One by One Array index value.
In this above example, we have made 2 Arrays. First Array has values 1,2,3, 4, and the other array has values 6,7,4.
If you want to merge two arrays then you should use the array merge function which will merge these two arrays into an array.
There are three types of arrays.
1. Index Array .
PHP index starts from 0. We can store number, string, an object in the PHP array.
All array elements assigned to an index number by default.
Learn Index Array
2.Two dimensional array .Two dimensional array have rows and columns
two-dimensional array is, in essence, a list of one-dimensional arrays. To declare
a two-dimensional integer array of size [x][y].
Learn Two dimensional Array
An associative array is one of the most reliable array in PHP. In an associative array, we can associate the name with each array of elements in PHP using the => symbol.
Learn Associative Array
Payment form by PayUmoney gateway with GST invoice,email | PHP software
Complete Blog CMS system in PHP with MYSQL database | PHP scripts
Paypal payment form with email, invoice generator in PHP website | Scripts