90 likes | 224 Views
Arrays :. Specifying with Array () : - It takes a Certain number of comma – Seprated key => value pairs. Syntax : array( [ key => ] value ……. ). One Dimensional Arrays :. <? php $a [ ] =12 ; $a [ ] =32 ; $a [ ] =12.32 ; $a [ ] = “ viral Koradiya ”;
E N D
Arrays : Specifying with Array () : - It takes a Certain number of comma – Seprated key => value pairs. Syntax : array( [ key => ] value ……. )
One Dimensional Arrays : <?php $a [ ] =12 ; $a [ ] =32 ; $a [ ] =12.32 ; $a [ ] = “ viral Koradiya”; Print $a [ 0 ].”<br>” ; Print $a [ 1 ].”<br>” ; Print $a [ 2 ].”<br>” ; Print $a [ 3 ].”<br>” ; ?>
Two Dimensional Arrays : <?php $a [ 0 ] [ 0 ] =12 ; $a [ 0 ] [ 1 ] =32 ; $a [ 1 ] [ 0 ] =12.32 ; $a [ 1 ] [ 1 ] = “ viral Koradiya”; Print “$a [ 0 ] [ 0 ]”. “   ;” .“$a [ 0 ] [ 1 ]”.” ” Print “<br>’ Print “$a [ 1 ] [ 0 ]”.” ” Print “$a [ 1 ] [ 1 ] ;” ?>
For Loop With Arrays : <?php $a [ 0 ] [ 0 ] = 12 ; $a [ 0 ] [ 1 ] = 32 ; $a [ 1 ] [ 0 ] = 12.32 ; $a [ 1 ] [ 1 ] = “ viral ”; For ($i = 0 ; $i <= 1 ; $i++ ) { for($j = 0 ; $j <= 2 ; $j++ ) { print $a [ $i ] [ $j ]. ”<br>” ; } } ?>
Foreach Loop With Arrays : <?php $ar = array ( 10,110,210.10, “VIRAL” ); Foreach( $ar as $new1 => $new2) { print “Keys [“.$new1.”]”. “<b>value</b>”.$new2. “<br>”; } ?>
Associative Arrays : Example 1 : $ages = array(“Viral “ => 10 , ”Meet” => 20, “Swat” =>30 );
Associative Arrays : Example 2 : $ages [ ‘viral’ ] = “20 “; $ages [ ‘vijay’ ] = “25 “; $ages [ ‘Meet’ ] = “30 “; ~> Id Keys can be used in a Script :
Associative Arrays : Example 3 : <?php $ages [ ‘viral’ ] = “20 “; $ages [ ‘vijay’ ] = “25 “; $ages [ ‘Meet’ ] = “30 “; Echo “Viral Age is :”.$ages[ ‘Viral ‘ ]. “Years is old. “ ?>
Associative Arrays : Example 4 : <?php $ar =array(5,”One”=>34, “Two”=>50, 70.62, “Hello”=>”viral”); Foreach( $ar as $new1 => $new2 ) { print $new1.”=>”. $new2.”<br>”; } ?>