To get the first element of an array in PHP, the code is as follows −
Example
<?php $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110", "t"=>"115", "u"=>"103", "v"=>"105", "w"=>"125" ); echo "Array value ...\n"; echo "Value 1 = " . $arr["p"], "\n"; ?>
Output
This will produce the following output−
Array value ... Value 1 = 150
Example
Let us now see another example −
<?php $arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110", "t"=>"115", "u"=>"103", "v"=>"105", "w"=>"125" ); echo "Value 1 = " .reset($arr); ?>
Output
This will produce the following output −
Value 1 = 150