Wednesday, 28 January 2015

Arrays Key

In php we can also set keys for each element in array as below:

<?php

// define an array
$arraykeys = array('keyname1' => 'element1', 'keyname2' => 'element2', 'keyname3' => 'element3', 'keyetc' => 'etc..');
print_r($arraykeys); 

//print output Array ( [keyname1] => element1 [keyname2] => element2 [keyname3] => element3 [keyetc] => etc.. )

//we can also get single key as follow:

print_r($arraykeys['keyname1']); 

// print output element1



?>

No comments: