hassan Posted August 6, 2015 Share Posted August 6, 2015 Hi In the book on page 57 it states in the tips "Because PHP is lax with its variablestructures, an array can even use a combination of numbers and strings as its keys. The only important rule is that the keys of an array must each be unique." How can you get duplicate keys? I tried experimenting wrote the following: <?phpecho "<p>This text was generated by PHP!</p>";echo "hello word<br>";$states['IL'] = "hellow";$states['IM'] = "IM hellow";$states['IM'] = "IM hellow2";echo $states['IL'];echo "<br>";echo $states['IM'];echo "<br>";echo "Test this: {$states['IM']}";?> It simply assigns the new value to the array and not let me create a duplicate? Link to comment Share on other sites More sharing options...
Larry Posted August 7, 2015 Share Posted August 7, 2015 This is correct. You cannot use duplicate keys, which is why I state each key must be unique. As you've discovered, using a duplicate key results in overwriting a previously stored value at that key. Link to comment Share on other sites More sharing options...
hassan Posted August 7, 2015 Author Share Posted August 7, 2015 Thank again Sorry for asking too many questions ... I am enjoying it ... I started learning a while ago then stopped and now started again this time not to quit ... I realised alot of things I simply glossed over ... or didt type out all the code nor experimented much with the code ... this time round I am doing that and its alot more fun and I am enjoying it ... I think by being curious and trying out different things giving me more confidence to write my own little snippets ... Link to comment Share on other sites More sharing options...
Larry Posted August 8, 2015 Share Posted August 8, 2015 I'm glad you're learning new things and enjoying it. It's also great to see that you're experimenting and trying other things in order to fully grasp the concepts. Link to comment Share on other sites More sharing options...
Recommended Posts