SmokingMan Posted January 6, 2008 Share Posted January 6, 2008 As I strive to learn PHP, I see two operators used in assigning values to arrays. They are "=" and "=>". I can't seem to find any explanation as to the differences between them and when one or the other should be used. Can someone clear this up for me?I know this is probably VERY simple, but to a newbie to PHP like myself...not so much. Link to comment Share on other sites More sharing options...
jhecht Posted January 6, 2008 Share Posted January 6, 2008 I'm guessing the syntaxes you see these both in are as followed: $arrayOne = array();// array defined, no values;$arrayOne['something'] = 'value';$arrayOne['something2']= 'other value';$arrayOne[] = 'Value appended with a numerical index instead of a string';$arrayTwo = array('key1'=>'someValue','keyTwo'='OtherValue');$arrayTwo['meow'] = 'cat'; The first is just an equals, nothing very different about it. You will access the values through the given key names or indexes.Now the second is saying that we create an array, obviously, but this array (sort of) has same base values. Say i wanted to print out someValue, i would callecho $arrayTwo['key1']. the only difference between a '=' and an '=>' is that the '=' is used when doing the first example, the '=>' is used when putting values directly into an array. This is good if its an array of things you don't need to remember(such as parser data). if you will have a variable for the array, you could use either. It doesn't matter Link to comment Share on other sites More sharing options...
SmokingMan Posted January 6, 2008 Author Share Posted January 6, 2008 Thanks, I'm learning this in my spare time at home and sometimes the tutorials don't go into the depth I would like. So I'll probably have my fair share of stoopid questions for a while until I get a little more comfortable with PHP Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.