There are Three Types of Arrays in PHP -
1. ) Indexed Arrays - Arrays with a numeric index
2. ) Associative Arrays - Arrays with ( Keys & Value Paire )
3.) Multidimensional Arrays - Arrays containing one or more arrays in single array.
Example of Indexed Arrays:
<?php
/Example Of Indexed arrays:
$arr = array(10,20,30,40,50,60);
?>
Example of Associative Arrays:
<?php
//Example Of Associative arrays:
$arr = array("a"=>"10", "b"=>"20", "c"=>"30","d"=>"40");
foreach($arr as $z => $z_value) {
echo "Key=" . $z . ", Value=" . $z_value;
echo "<br>";
}
?>
Example of Multidimensional Arrays:
<?php
#Example of Multidimensional Arrays:
$student = array (
array("Ram",10,15),
array("Shyam",9,15),
array("Sahab",11,16),
array("Ravi",12,17)
);
echo $student[0][0].": Class: ".$student[0][1].", Age: ".$student[0][2].".<br>";
echo $student[1][0].": Class: ".$student[1][1].", Age: ".$student[1][2].".<br>";
echo $student[2][0].": Class: ".$student[2][1].", Age: ".$student[2][2].".<br>";
echo $student[3][0].": Class: ".$student[3][1].", Age: ".$student[3][2].".<br>";
?>
0 Comments