Example -
In php there are 3 types of arrays.
1. Index
arrays
2. Associative
arrays
3. Multi-dimensional
Arrays.
Code and Syntax –
//Index arrays
$emp=array("e1","ba","cd");
$alength=count($emp); // find the length of emp array.
//Associative arrays
$sal=array("sagar"=>"35000","amol"=>"390907","Jockey"=>"43000");
//$sal['ganesh']="398985";
//To iterate the associative array use below code
<?php
foreach($sal as $key=>$val)
{
echo "Key=" . $key . ", Value=" . $val;
echo "<br>";
}
?>
foreach($sal as $key=>$val)
{
echo "Key=" . $key . ", Value=" . $val;
echo "<br>";
}
?>
Explanation
–
In above examples, we have created indexed arrays
and associative arrays. Difference between 2 arrays is that in index arrays we
store the values based upon numerical index. While in associative array, we store
the values based upon key.
For more
php questions and answers, dumps,tutorials for beginners and experienced people
visit http://www.top-php-interview-questions.blogspot.in If you find any errors while executing this
program, you can make your comments or mail me at reply2sagar@gmail.com
No comments:
Post a Comment