Ken2k7 Posted December 25, 2007 Share Posted December 25, 2007 Almost all forum scripts have some sort of lang.php which holds an array with output lines. $arr = array(); $arr = array( 'SOMETHING' => "SOMETHING ELSE", 'SOMETHING 1' => "SOMETHING ELSE 1", . . . ); ?> My question is how does => work and if I plan to use something like this too, how would I go about getting the values? Thanks in advance, Ken Quote Link to comment Share on other sites More sharing options...
revraz Posted December 25, 2007 Share Posted December 25, 2007 => is assigning a value to an index, or do you mean -> ? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 25, 2007 Share Posted December 25, 2007 It's a way of specifying the key in order to create an associative array instead of the default enumerated array. <?php $array = array('key' => 'value'); echo $array['key']; // output: value $array = array('value'); echo $array[0]; //output: value ?> See: http://www.php.net/manual/en/language.types.array.php Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted December 25, 2007 Author Share Posted December 25, 2007 Thanks Daniel. Final question on this matter: can I use a loop for this? Edit: okay read the link you placed up Daniel. Question now is: can you explain what the => does in this? And what does $array as $i mean? <?php foreach ($array as $i => $value) { unset($array[$i]); } ?> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 25, 2007 Share Posted December 25, 2007 It signifies the same. The thing to the right of the => operator is the value and to the left is the key. In other words: You are looping through the array $array and at each iteration you can access the value as $value and the key as $i inside the loop. You can read more about foreach here: http://php.net/foreach Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted December 25, 2007 Author Share Posted December 25, 2007 Oh okay. Just making sure on one thing here. So rather than having a key, can I use the foreach loop as such: <?php foreach ($array as $i) { unset($array[$i]); } ?> Unless the $value plays a special role in that foreach loop :S Which I have no idea what it does. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 25, 2007 Share Posted December 25, 2007 No, if the => operator is omitted the variable after as will contain the value. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted December 25, 2007 Author Share Posted December 25, 2007 Oh I think I get this. Thanks Daniel. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.