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 Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/ 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 -> ? Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-422998 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 Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423002 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]); } ?> Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423003 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 Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423005 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. Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423010 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. Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423013 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. Link to comment https://forums.phpfreaks.com/topic/83162-solved-arrays/#findComment-423015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.