Wednesday, 28 January 2015

Array Declaration Alternative Method

Arrays can also declare as:

<?php

// define an array
$myarray[0] = 'element1';
$myarray[1] = 'element2';
$myarray[2] = 'element3'; 

print_r($myarray);
//print output Array ( [0] => element1 [1] => element2 [2] => element3 )
 // OR

// define an array
$myarray[keyname0] = 'element1'; 
$myarray[keyname1] = 'element2'; 
$myarray[keyname2] = 'element3'; 

print_r($myarray);

//print output Array ( [0] => element1 [1] => element2 [2] => element3 )

?>

No comments: