php code for Numeric array, Associative array and Multi dimetional Array as below
PHP code for Array
Example :
<?
echo "<br/> Numeric array</br>";
$arr=array(1=>"India",2=>"China",3=>"canada");
echo "<br/> Country: ".$arr[2];
$arr[4]="Sri Lanka";
echo "<br/> after push</br>";
array_push($arr,"USA");
print_r($arr);
echo "<br/> After pop</br>";
array_pop($arr);
print_r($arr);
$arr1=array("gujarat","maharastra","MP");
echo "<br/> Array</br>";
print_r($arr1);
echo "<br/> Associative array</br>";
$strarr=array("Domestricanimal"=>"dog","bird"=>"crow","wildanimal"=>"tiger");
echo "<br/>".$strarr['wildanimal'];
echo "<br/>Multi dimetional Array</br>";
$multiarr=array("animal"=>array("Domestricanimal"=>"dog","wildanimal"=>"tiger"),"birds"=>"parrot");
print_r($multiarr);
echo "<br>".$multiarr['animal']['wildanimal'];
$arrvar=array(11,22,33,44,55,66);
$arrvar[2]=99;
array_push($arrvar,77,88);
foreach($arrvar as $key=>$val)
{
echo "<br>".$key ." : ".$val;
}
for($i=0;$i<count($arrvar);$i++)
{
echo "<br/> $i :".$arrvar[$i];
}
$arr=array(1=>"India",2=>"China",3=>"canada");
$slice=array_slice($arr,1,1);
print_r($slice);
?>
Output :
Comments