Types of Array in PHP
An Array is assigned to
be a single variable , but can hold dozens of individual piecies of information.
Types of Array
1. Numeric Array
2. Associative Array
3. Multidimensional Array
1. Numeric Array
In numeric array have to create only elements, id
will be automatically assign to the element.
Example:
<?php
$a = array("a","b","c");
print_r($a);
?>
Output:
Array([0]=>a [1] =>
b [2]=> c)
2. Associative Array
This kind array have id and elements both are
created
Example :
<?php
$a = array("1"=>"a","2"=>"b","3"=>"c");
print_r($a);
?>
Output :
Array([1]=>a [2] =>
b [3]=> c)
Note : The above out in which [1], [2], [3] are ids
And a,b,c are elements
3. Multidimensional Array
Multidimensional array means we have to create
array within array.
Example
<?php
$a = array("a","b"=>array("x", "y"), "c");
print_r($a);
?>
Output
Array([0]=>a, [b]=>Array([0]=>x
[1]=>y)[1]=>c)
Comments
Post a Comment