Associative Array
By S.Tanveer
Published: 14 Aug 2006
Array In PHP
Associative Array in PHP
In Associative array data will store through String index value .For example To store the student marks in an array. We store the each student marks with there own name. The name are stored as index and marks as there values.
$marks = array("Ali" => 400, "Javeed" => 600, "Azra" => 500) ;
you can print these valu
echo $marks['Ali'] . "
"; echo $marks['Javeed'] . "
"; echo $marks['Azra'] . "
";
You can also use the forech loop which is best way of retrieving the data form array.
foreach($marks as $x => $x_value) { echo "name=" . $x . "Marks=" . $x_value . "
" ; } ?>
Two Dimensional String Index Associative Array
You also store the data in two dimensional string index array or in Associative array.
For example we create a Two dimensional with string Index. In which store the Name ,marks, and Grade of Student.
array('Marks' => 500, 'Grade' => "A"), "Qasim"=> array('Marks' => 530, 'Grade' => "A"), "Javeed"=> array('Marks' => 450, 'Grade' => "B") ); ?>
You can display these value form two dimension string index array in the following way: