Page 140 - Open Soource Technologies 304.indd
P. 140
Web Technologies-I
Notes $array=array(“Hello”=>1,”Hi”=>2,”Hei”=>3);
asort($array);
foreach($array as $key=>$value){
echo “Key: “.$key.”Value: “.$value.”<br/>”;
}
echo “<br/>”;
$array=array(“Hello”=>1,”Hi”=>2,”Hei”=>3);
ksort($array);
foreach($array as $key=>$value){
echo “Key: “.$key.”Value: “.$value.”<br/>”;
?>
Output:
3Hello
New
World
Hei
Hello
Hi
Key: HelloValue: 1
Key: HiValue: 2
Key: HeiValue: 3
Key: HeiValue: 3
Key: HelloValue: 1
Key: HiValue: 2
In the oracle basically, an associative array is a two-column table. The first
column of the associative array is the index. The second column of the
associative array is the data element. The index value of the associative array
is used to locate the data element.
6.2 Identifying Elements of an Array
You can access specific values from an array using the array variable’s name, followed by the
element’s key (sometimes called the index) within square brackets:
$age[‘Fred’] $shows[2]
The key can be either a string or an integer. String values that are equivalent to integer numbers
(without leading zeros) are treated as integers. Thus, $array[3] and $array[‘3’] reference the same
element, but $array[‘03’] references a different element. Negative numbers are valid keys, and
they do not specify positions from the end of the array as they do in Perl.
134 LOVELY PROFESSIONAL UNIVERSITY